Docker installation and basic commands

Installation:
yum install docker

can use yum to upgrade to the latest version
yum update docker

installation is successful
docker --version #start service docker start #stop

service docker stop #restart service docker restart starts successfully, view the container information, including the location where the docker image is stored docker info View the local image docker images Search the image docker search <image> Pull the image docker pull image_name After the grab is successful, you can view the local image with docker images



















commit image

docker push image_name

Start the container
docker run -i -t -v /root/software/:/mnt/software/ --privileged=true 2a392a47afc5
docker run <relevant parameters> <image ID> <initial command>
The relevant parameters include:
-i: means Run the container in interactive mode
-t: Indicates that the container will enter its command line after startup
-v: Indicates which local directory needs to be mounted into the container, the format -v <host directory>: <container directory>
Assuming that all our installations The programs are placed in the /root/software/ directory of the host, and now they need to be mounted to the /mnt/software/ directory of the container.

For example:
docker run --name zcycentos_nginx_v1 -d -p 80:80 nginx:v1
docker run --name zcycentos -i -t 0a2bad7da9b5 
--name: give a container a custom name, an image, and multiple containers can be run by running Define the name to distinguish
-p host port: port in the container

nginx:v1 is the image name, or imagesid


Enter the running container
docker attach dabfb413d8cf [container ID]
container id, you can view it with docker ps


Make an image Note. Dockerfile representing the current directory --rm=true Delete the image generated during the image making process

docker build -t image name:version. --rm=true

Delete the image
docker rmi docker.io/tomcat:7.0.77-jre7 or docker rmi b39c68b7af30

Check which containers are currently running
docker ps

Check all containers
docker ps -a

Start, stop, restart container commands:
docker start container_name/container_id
docker stop container_name/container_id
docker restart container_name/container_id

The command to delete the container (after the container is stopped, the container still exists and can be restarted or deleted):

docker rm container_name/container_id

After the container starts, enter the container
docker attach container_name/container_id


View command execution log

docker logs container name/id

View container-related information, including volumes, etc.

docker inspect container name/id


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325893505&siteId=291194637