Docker image, container, Dockerfile common command filtering summary

Article directory

!! And learn and summarize~~~

1. Image command

view all images

docker images

pull an image

docker pull remote images

delete the specified image

run image

docker run -dit the id of the images # run an images 
-d # run as a daemon 
-p local port: port inside docker # port mapping

Import and export of images and local files

The image is exported to the local:

docker save image id > local
 file.tar # eg: 
# docker save f95adbdaa41c > handles_firefox.tar

Import locally to [docker] image

docker load < local
 file.tar # Example: 
# docker load < handles_firefox.tar

2. [Container] command

show running docker

docker ps
docker ps -a

restart the container

docker start container ID

Stop running the container

docker stop container id  # stop a docker

delete container

docker rm Container ID1 Container ID2 Container ID3

Local content and docker container content are transferred to each other

Transfer files from the machine to the inside of the docker container

docker cp local content container id:
 //usr/....path# Example: docker cp index.html 17adwicm13ji://usr/share

Transfer from docker container, to this machine

docker cp container id: container file path native path

Save changes to the container

Because docker’s changes in the container are temporary

docker commit -m 'remark' container id custom repository name 
 # Example: docker commit -m 'test' 17adwicm13ji TestName

Check container information

This command can print a lot of docker information

docker inspect Container ID/IMAGE

Go inside the container and open a [command line]

docker exec -it public ID /bin/bash
 # uninstall:docker exec -it f107a3df2958 /bin/bash

heavy naming container

docker rename original container name new container name


File command:

FROM image name # Inherited from image 
MAINTAINER Author name # Declare the builder of the 
dockerfile # CMD Command # The command to run in the container 
RUN # Run inside the container 
# Example: RUN apt-get update 
EXPOSE # Expose port 
ENV # Set environment variable 
ENTRYPOINT # Specify the startup entry, if not specified, use cmd by default

Construct the mirror:

docker build dockerfile path
 # For example: docker build -t test_docker . # Indicates to use all files in the current path 
# Parameters: 
-t custom TAG name

Leave a Comment

Your email address will not be published. Required fields are marked *