Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

This article mainly describes some common commands in the process of using Docker, so that you can refer to them in the process of using later.

Common Docker commands

Docker run

  • Run: Download (pull) create (create) Run start
--name Defines the container name --rm This is a temporary container -- IP specifies the container IP -p specifies the mapping port -d background startup -v Sets the directory to hang in (through: split even a file, both must write the absolute path) -h sets the hostnameCopy the code
docker run --name myNginx --rm -p 12346:80 nginx
Copy the code
  • Logs: View logs, view container details inspect
docker logs myNginx
Copy the code
  • Exec-it enters the container
#Into the container
docker exec -it myNginx bash

#View Nginx configuration
cat /etc/nginx/conf.d/default.conf
Copy the code
  • View running containers
#View the currently running container
docker ps

#View all containers
docker ps -a
Copy the code

Docker mirror

  • Pull the download
  • Images Displays the current local mirror repository
  • Search Search for images
docker search java
Copy the code
  • Rmi Deletes a mirror
# Query all mirrors
docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssm_nginx           latest              7f48053b7f39        11 minutes ago      127MB
nginx               latest              a1523e859360        2 days ago          127MB

# delete mirror
docker rmi nginx:latest

Untagged: nginx:latest
Untagged: nginx@sha256:380eb808e2a3b0dd954f92c1cae2f845e6558a15037efefcabc5b4e03d666d03
Copy the code
  • Mirror construction
#1. Write Dockerfile
vim Dockerfile

#2. File content
FROM nginx
RUN echo '<h1>This is Test Nginx</h1>' > /usr/share/nginx/html/index.html

#3. Build an image
docker build -t ssm_nginx ./

#4. Query mirror information
docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ssm_nginx           latest              7f48053b7f39        33 seconds ago      127MB
nginx               latest              a1523e859360        2 days ago          127MB

#5. Run the image
docker run --name myNginx --rm -p 80:80 ssm_nginx
Copy the code

The resources

  • www.runoob.com/docker/dock…