docker installation and use under CentOS 7

Posted by Scorptique on Thu, 21 May 2020 16:38:11 +0200

docker start stop

sudo systemctl start docker.service 
sudo systemctl stop docker.service
sudo systemctl restart docker.service 
sudo systemctl status docker.service 
sudo systemctl enable docker

sudo docker ps -a ## <-- List existing images ##
sudo docker stop 17dd4ab4cda2 ##<-- 17dd4ab4cda2 by container id ##
sudo docker rm 17dd4ab4cda2 ##<-- delete container id ##
sudo docker rmi image_name ##<-- delete images ##
sudo docker ps -a | grep Exit | awk '{print $1}' | xargs docker rm ##<-- delete exit Of images ##
docker info  ## <-- confirm Docker Is it installed correctly ##
# docker rm --force `docker ps -qa`

Problems encountered

After the docker is started by cenOS, the virtual machine fails to ping?

The reason is that the docker daemons use 172.17.0.1 as the network segment by default. You can find the network of docker 0 through ifconfig, which conflicts with the network segment of the host;

resolvent: https://forums.docker.com/t/change-default-docker0-bridge-ip-address/30470/8 , i.e. add under / etc/docker daemon.json File, modify docker to start the default network segment

Execution_ ifconfig docker0 down _ that will do

ifconfig command

` docker info`

Reuslts in Get http:///var/run/docker.sock/v1.12/info: dial unix /var/run/docker.sock: permission denied

resolvent

Add docker user group

sudo groupadd docker

Give all users of the user group the rights of docker

sudo usermod -a -G docker $USER

Exit ssh client and log in again

docker installation under cenOS

yum install docker

yum install epel-release

yum install docker-io

systemctl enable docker

systemctl start docker  
systemctl status docker

docker run hello-world

Publish Vue application configuration in Node mode

Dockerfile

FROM node:9.11.1-alpine

# install simple http server for serving static content
RUN npm install -g http-server

# make the 'app' folder the current working directory
WORKDIR /app

# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./

# install project dependencies
RUN npm install

# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .

# build app for production with minification
RUN npm run build

EXPOSE 8888
CMD [ "http-server", "dist" ,"-p 8888"]

start.sh

#!/bin/sh

## start docker
cd frontend/tms
echo "Delete previous container..."
docker rm --force `docker ps -qa`
echo "Generate image..."
docker build -t  tms_frontend:1.0 .
echo "Start container..."
docker run -p 8888:8888 --net=host --rm --name tms_frontend  tms_frontend:1.0  &

Docker compose installation

sudo curl -L https://github.com/docker/compose/releases/download/1.20.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose

sudo chmod a+x /usr/local/bin/docker-compose
docker-compose --version

Build docker private service

Open private server port 5000

Use the official registry image to start the local private warehouse

firewall-cmd --zone=public --add-port=5000/tcp --permanent
docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry registry
docker start $(docker ps -l | grep registry | awk '{print $1}') #Start warehouse

If the port is not turned on, there is a connection rejected error when you view the image in the registry in pull image and curl image

Configure private ip address

The docker registry uses https, so when downloading a remote image with the docker pull command, an error will be reported if the remote docker registry is non https

To solve this problem, you need to add startup parameters when starting docker server

Open / etc/docker/daemon.json , add secure registers

After modifying the configuration, execute the following command

systemctl daemon-reload
sudo systemctl restart docker.service

Preparing the mirror

docker pull hello-world
docker tag bf756fb1ae65 172.18.0.57:5000/hello:latest
docker push 172.18.0.57:5000/hello
curl -X GET http://172.18.0.57:5000/v2/_catalog

Topics: Operation & Maintenance Docker sudo JSON network