Summary of common basic commands for learning Docker

  • 2020-05-17 07:02:16
  • OfStack

preface

Docker is an ultra-lightweight virtual machine implemented in a novel way. It is still very different from VM in terms of implementation principle and application. It is technically known as application container (Application Container). The following article gives a brief introduction to some of the basic commands commonly used by Docker.


#  in ubuntu Installed in the docker
$ sudo apt-get install docker.io

#  To view docker Version information 
$ docker version

#  Check the installation docker The information of 
$ docker info

#  Look at the machine Docker Which mirror images exist in 
$ docker images

#  retrieve image
$ docker search ubuntu:14.04

#  in docker To derive ubuntu The mirror 
$ docker pull ubuntu:14.04

#  According to 1 A mirror image of history 
$ docker history birdben/ubuntu:v1

#  list 1 A file or object that has been changed in a container 
$ docker diff birdben/ubuntu:v1

#  from 1 Fetch the log from the container 
$ docker logs birdben/ubuntu:v1

#  According to 1 Process information in a running container 
$ docker top birdben/ubuntu:v1

#  Copy the file from the container / Directory to local 1 A path 
$ docker cp ID:/container_path to_path

#  Lists all currently running containers 
$ docker ps

#  List all containers 
$ docker ps -a

#  Recently listed 1 A secondary startup container 
$ docker ps -l

#  View information about the container 
$ docker inspect $CONTAINER_ID

#  According to the container IP The address and port number, if the output is empty, are not configured IP Address (different Docker The container can pass through this IP Mutual address access) 
$ docker inspect --format='{{.NetworkSettings.IPAddress}}' $CONTAINER_ID

#  Save the changes to the container  
$ docker commit -m "Added ssh from ubuntu14.04" -a "birdben" 6s56d43f627f3 birdben/ubuntu:v1

#  Parameters: 
# -m Parameter is used to specify the information to be submitted. 
# -a Where user information can be specified; 
# 6s56d43f627f3 Represents the time of the container id ; 
# birdben/ubuntu:v1 Specify the user name, repository name, and the target image  tag  Information. 

#  build 1 A container  
$ docker build -t="birdben/ubuntu:v1" .

#  Parameters: 
# -t Specify the image for the build 1 Label, easy to remember / The index etc. 
# .  The specified Dockerfile File in the current directory, can also be replaced by 1 A specific  Dockerfile  The path. 

#  in docker Running in the ubuntu The mirror 
$ docker run < Related parameters > < The mirror  ID> < The initial order >

#  Daemon mode enabled 
$ docker run -it ubuntu:14.04

#  Interactive mode startup 
$ docker run -it ubuntu:14.04 /bin/bash

#  Specifies the port number to launch 
$ docker run -p 80:80 birdben/ubuntu:v1

#  Specify configuration startup 
$ sudo docker run -d -p 10.211.55.4:9999:22 birdben/ubuntu:v1 '/usr/sbin/sshd' -D

#  Parameters: 
# -d : indicates that the log will not appear on the output terminal if it is executed in "daemon mode". 
# -i : means to run the container in "interactive mode", -i  Leave the container's standard input open 
# -t : means that the container will enter its command line after startup. -t  Option to Docker distribution 1 Two pseudo-terminals ( pseudo-tty ) and bind to the container's standard input 
# -v : indicates which local directory needs to be mounted into the container. The format is: -v < Host directory >:< Container directory > . -v  Tag to create 1 Data volume and mount it into the container. in 1 time  run  Can mount multiple data volumes. 
# -p : represents the port mapping between the host and the container  22  The port is mapped to the host  9999  Port, so it's exposed to the outside world  9999  Port, available through  Docker  The bridge accesses the inside of the container  22  The port. 
#  Note: the host is used here  IP  Address: 10.211.55.4 , and the exposed port number  9999 , which maps the port number inside the container  22 . ssh External access required: ssh root@10.211.55.4 -p 9999
#  Don't 1 Always use "mirror image  ID ", you can also use the "warehouse name : Tag name" 

# start  Start the container 
$ docker start 117843ade696117843ade696
# stop  Stop the running container 
$ docker stop 117843ade696117843ade696
# restart  Restart the container 
$ docker restart 117843ade696117843ade696
# rm  Remove the container 
$ docker rm 117843ade696117843ade696
# rmi  Remove the mirror 
$ docker rmi ed9c93747fe1Deleted

#  The login Docker Hub center 
$ docker login

#  Release to upload image ( push ) 
$ docker push birdben/ubuntu:v1

When creating containers using docker run, Docker runs in the background with standard operations such as:

1. Check whether the specified image exists locally and download it from the public warehouse if it does not

Create and start a container using an image

3. Assign a file system and mount a read-write layer outside a read-only mirror layer

4. Bridge a virtual interface from the bridge interface configured by the host to the container

5. Configure 1 ip address to the container from the address pool

Execute the user-specified application

7. The container is terminated after execution

conclusion

This is a summary of the basic commands commonly used by Docker. I hope it can be helpful to friends in need. If you have any questions, please leave a message to communicate.


Related articles: