Docker small instance

If the text continues, the book will continue. Today we are going to talk about operations related to Docker image containers

directory

  • It’s time for Docker: 1 Docker tutorial
  • It is time for Docker: 2 to install and cancel sudo execution Docker
  • It is time for Docker: 3 Docker small instances
  • Docker: 3.1 Docker19 command quick reference table
  • It is time for Docker: 4 Dockerfile to create the image
  • It is time for Docker: 5 volumes to be independent of persistent storage outside the container

Create a file

vim index.html <html> <h1>docker is fun! </h1> </html>Copy the code

Deployed Nginx

/ / - p: 8081 80 8081 map to 80 | - d daemon docker run - d - 8080 p: 80 nginx / / verification curl http://127.0.0.1:8080 docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 19d1b0186d1a nginx "nginx -g 'daemon of..." 12 seconds ago Up 11 seconds 0.0.0.0:8081->80/ TCP nginxServerCopy the code

Copy files to docker

Docker exec it [CONTAINER ID] bash docker exec it [CONTAINER ID] bash Find the nginx directory, Find. -name "nginx" // list all files named nginx under the current directory and its subdirectories exit // exit docker cp index.html 19 d1b0186d1a: / / usr/share/nginx/HTML/curl http://127.0.0.1:8080 / validationCopy the code

Save container changes

Docker commit -m 'add index. Html2 / usr/share/nginx/HTML' 19 d1b0186d1a nginx - fun / / return: sha256:ddccfc4cb7bec3e81ffa580826096adb94b77c7b4e859521af32ad5fa68f9d5d docker stop 19d1b0186d1a docker run -d -p 8080:80 nginx-fun // Verify curl http://127.0.0.1:8080Copy the code

Command summary

The command instructions
docker pull Get the image
docker build To create the image
docker images To list the image
docker run [CONTAINER NAME] Operation of the container
docker container ls Lists running Containers
docker container ls -a List all containers (terminated containers)
docker container stop [CONTAINER ID] Termination of the container
docker container logs Gets the container output
docker ps List the container
docker rm Remove the container
docker rmi Delete the image
docker exec -it [CONTAINER ID] bash Enter the Container and run commands. It is not recommended to use the Docker attach commandexitTerminate the container when
docker cp [SOURCE PATH] [CONTAINER ID]:/[TARGET PATH] Copy files inside the container
docker commit -m ‘[MESSAGE]’ [CONTAINER ID] [IMAGE NAME] Save the changes as the new image

More on that next time

Original is not easy, if you think my article is helpful to you, please click to encourage