Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to install and use Docker

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to install and use Docker". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to install and use Docker" together!

how to install

Docker installation is very simple.

Windows or Mac users:

Download the installation package for installation. Docker Desktop for Mac (macOS) Docker Desktop for Windows

Linux users (for example, ubuntu):

There are three ways (depending on your network):

Install using source (source environment needs to be set up in advance)

$ sudo apt-get install docker-ce docker-ce-cli containerd.io

Download the offline package for installation (https://download.docker.com/linux/ubuntu/dists/)

$ sudo dpkg -i /path/to/package.deb

Install using online scripts

$ curl -fsSL https://get.docker.com-o get-docker.sh $ sudo sh get-docker.sh Basic usage

All docker commands start with docker, followed by spaces and subcommands to perform the corresponding operations. For detailed command line documentation, see official website: docs.docker.com/engine/reference/commandline/cli/

Start a container

run means start, and need to specify an image file, docker with this image file as a template to start a container.

$ docker run -d -p 80:80 docker/getting-started

-d indicates background operation

-p 80:80 means port mapping maps local port 80 to container port 80

docker/getting-started image file (this image is the tutorial image provided by the official website. After starting, you can open http://localhost/tutorial/in your browser to enter docker novice tutorial)

View running containers

ps View running containers, each running container will have a containerId, similar to the pid returned by the ps command in Linux.

$ docker ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8234ab6bc530 docker/getting-started "/docker-entrypoint.…" 11 seconds ago Up 9 seconds 0.0.0.0:80->80/tcp hopeful_hamilton

-a means all, see all, including stopped

Stop a container

To stop a container, a containerId is required to indicate which container to stop. And the stop command is idempotent, so you can think of it as telling the docker engine to keep the specified container stopped.

$ docker stop 8234ab6bc530

At this point, if you use ps to view the container, you will find that the container has stopped, and you can see that the status of the container is Exited (0).

$ docker ps -af 'id=8234ab6bc530'CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES8234ab6bc530 docker/getting-started "/docker-entrypoint.…" 19 minutes ago Exited (0) 3 minutes ago hopeful_hamilton

-af is-a (--all) for all and-f (--filter) for combinations filtered by condition,'id=8234ab6bc530' is an argument to-f for containers with id = 8234ab6bc530.

Start a stopped container

start To start a stopped container, a containerId is required to indicate the container. The start command is idempotent, just like the stop command, and can be thought of as telling the docker engine to keep the specified container started.

$ docker start 8234ab6bc5308234ab6bc530 delete a container

rm is used to delete a specified container, but it is not allowed to delete a running container.

$ docker rm 8234ab6bc530Error response from daemon: You cannot remove a running container 8234ab6bc530fa180da8a42b4c232761f604913c0adde06868dcd63bda841b37. Stop the container before attempting removal or force remove

So you need to stop, then delete.

$ docker stop 8234ab6bc5308234ab6bc530$ docker rm 8234ab6bc5308234ab6bc530 Appendix A Common Command Description

docker run : Create a new container and run a command argument:

-a stdin: Specify standard input and output content types, optional STDIN/STDOUT/STDERR;-d: Run container in background and return container ID;-i: Run container in interactive mode, usually used with-t;-P: Random port mapping, container internal port randomly mapped to host port-p: Specify port mapping, format: host (host) port: container port-t: reassign a dummy input terminal for container, usually used with-i;--name="nginx-lb": Specify a name for the container;--dns 8.8.8.8: Specify the DNS server used by the container, which is consistent with the host by default;--dns-search example.com: Specify the DNS search domain name of the container, which is consistent with the host by default;-h "mars": Specify the hostname of the container;-e username="ritchie": Set environment variables;--env-file=[]: Read environment variables from the specified file;--cpuset="0-2" or --cpuset="0,1,2": Bind the container to the specified CPU to run;-m : Set the maximum memory used by the container;--net="bridge": Specify the network connection type of the container, support bridge/host/none/container: four types;--link=[]: add a link to another container;--expose=[]: open a port or a group of ports;--volume , -v: bind a volume

docker exec : Executing commands in a running container Parameters:

-d : Detach mode: Run in background-i : Keep STDIN open even if there is no attachment-t : Assign a dummy terminal

docker cp : Used for copying data between containers and hosts. Parameters:

-L : Keep links in source target

docker logs : Get the log parameters of the container:

-f : trace log output--since : show all logs for a start time-t : show timestamp--tail : list only the latest N container logs

docker build: used to create images using Dockerfile

--build-arg=[] : Set variables at mirror creation;--cpu-shares : Set CPU usage weight;--cpu-period : Limit CPU CFS cycles;--cpu-quota : Limit CPU CFS quota;--cpuset-cpus : Specify CPU id used;--cpuset-mems : Specify the memory id to use;--disable-content-trust : Ignore check, open by default;-f : Specify the Dockerfile path to use;--force-rm : Delete intermediate containers during mirroring;--isolation : Use container isolation technology;--label=[] : Set metadata used by the mirror;-m : Set maximum memory;--memory-swap : Set maximum swap to memory +swap,"-1" means unlimited swap;--no-cache : Create mirror without cache;--pull : Try to update new version of mirror;--quiet, -q : Quiet mode, only output mirror ID after success;--rm : Delete intermediate container after setting mirror successfully;--shm-size : Sets the size of/dev/shm, the default is 64M;--ulimit :Ulimit configuration. -- squash : compresses all operations in Dockerfile into one layer. -- tag, -t: Name and tag of the image, usually in name:tag or name format; multiple tags can be set for a single image in a single build. -- network: default. During the construction of the RUN command network mode thanks to your reading, the above is "how to install and use Docker" content, after the study of this article, I believe that everyone on how to install and use Docker this problem has a deeper understanding, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report