March 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

Categories

March 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
25262728293031

docker commonly used command

docker commonly used command

1. View the docker information (version, info)

View the docker version
docker version

Displays information about the docker system
docker info

2. the operation of the image (search, pull, images, rmi, history)

Retrieve image
docker search image_name

Download image
docker pull image_name

List the mirror list; -a, –all = false Show all images; –no-trunc = false Do not truncate output; -q, –quiet = false Only show numeric IDs

docker images

Delete one or more mirrors; -f, –force = false Force; –no-prune = false Do not delete untagged parents

docker rmi image_name

Show a history of a mirror; –no-trunc = false Do not truncate output; -q, –quiet = false Only show numeric IDs

docker history image_name

3. Start the container

The docker container can be understood as a process that runs in a sandbox.

This sandbox contains the resources necessary for the process to run, including the file system, system class library, shell environment and so on.
But this sandbox by default is not running any program. You need to run a process in the sandbox to start a container.
This process is the only process of the container, so when the process ends, the container will be completely stopped.

Run the “echo” command in the container, output “hello word”
docker run image_name echo “hello word”

docker run -i -t image_name /bin/bash

docker run image_name apt-get install -y app_name

When executing the apt-get command, bring the -y parameter.
If you do not specify the -y parameter, the apt-get command will enter the interactive mode, requiring the user to enter a command to confirm, but in the docker environment is unable to respond to this interaction.
After the apt-get command completes, the container stops, but changes to the container are not lost.

4. View container (ps)

List all currently running containers

docker ps

List all the containers

docker ps -a

List the containers that were last started

docker ps -l

5. Save the container to commit (commit)

When you have made a change to a container (by running a command in the container), you can save the container changes, so that the next time you can save the latest state from the container.

Save the changes to the container; -a, –author = “” Author; -m, –message = “” Commit message
docker commit ID new_image_name
image is equivalent to the class, container equivalent to the example, but can be dynamically installed to the instance of the new software, and then use the commit order solidified into an image.

6. the operation of the container (rm, stop, start, kill, logs, diff, top, cp, restart, attach)

Remove all containers

docker rm `docker ps -a -q`

Remove a single container; -f, –force = false; -l, –link = false Remove the specified link and not the underlying container; -v, –volumes = false Remove the volumes associated to the container

docker rm name / id

Stop, start, kill a container

docker stop Name/ID
docker start Name/ID
docker kill Name/ID

Fetching from a container; -f, –follow = false Follow log output; -t, –timestamps = false Show timestamps

docker logs Name/ID

List a file or directory that is changed inside a container. The list list shows three events, A added, D deleted, C changed

docker diff Name/ID

Displays the process information inside a running container

docker top Name/ID

Copy the file / directory from the inside of the container to a local path

docker cp Name:/container_path to_path
docker cp ID:/container_path to_path

Restart a running container; -t, –time = 10 Number of seconds to try to stop for before killing the container, Default = 10

docker restart Name/ID

Attached to a running container; –no-stdin = false Do not attach stdin; –sig-proxy = true Proxify all received signal to the process

docker attach ID
The attach command allows you to view or affect a running container. You can attach the same container at the same time. You can also get out of a container, from CTRL-C.

7. Save and load the mirror (save, load)

When you need to migrate a mirror image to another machine, you need to save the image and load the mirror.

Save the mirror to a tar package; -o, –output = “” Write to an file
docker save image_name -o file_path
Load a tarball format image; -i, –input = “” Read from a tar archive file

docker load -i file_path

docker save image_name -o file_path

docker load -i file_path

Machine a
docker save image_name> /home/save.tar
Use scp will copy.tar Kaodao machine b, and then:
docker load /home/save.tar

docker load < /home/save.tar docker push new_image_name 8, log on registry server (login) Login server server; -e, - email = "" Email; -p, --password = "" Password; -u, --username = "" Username docker login 9. release image (push) Publish docker image docker push new_image_name 10. Use skills Remove all containers and mirrors (clean) Use a line command to clean up: docker ls $ (docker ps -a -q); docker rmi $ (docker images -q -a) Note: The shell in the $ () and `` similar to the implementation of the contents of the inside, the above script will appear as follows docker "kill" container, docker rmi Delete the mirror When there is no running container or no container at all, this will only prompt a warning message. When you want to try, this is a very good single line command. If you just want to delete all the containers, you can run the following command: docker kill $ (docker ps-a); docker rm $ (docker ps -a -q) docker kill $(docker ps -q) ; docker rm $(docker ps -a -q) ; docker rmi $(docker images -q -a)

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>