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

What are the basic commands of docker

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly introduces what the basic docker commands are, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.

Docker basic command

Docker file system

Docker image is a hierarchical design, compared with the full number of virtual machine images, less bootstrap bootfs, sharing the system kernel rootfs.

Configuration layer (container layer)

Commit Mirror

Docker commit-a = ""-m = "" docker_id image_name:tag

It's like taking a snapshot of a mirror.

Container data volume

Problem solving-> data persistence is essentially directory mount

Use data Volum

Method 1: directly use the command to mount-v

Docker run-it-v host directory: image_id / bin/bash named and anonymous mount # Anonymous mount docker run-d-P-- name nginx01-v / etc/nginx (container path) nginx# mount docker run-d-P-name nginx02-v xff-nginx:/etx/nginx (container path) nginxroot@hecs-39042:/var/lib/docker/volumes# ls4ad594eee4e6115b2852f5fa952176c799e99bf1d0cadaee9c581085b8e38b6e d309f4a3ce1aa585673548ed4fd43a3aa7a5ca4f86a5a52b236d02428b991379 xff-nginxbackingFsBlockDev Metadata.dbroot@hecs-39042:/var/lib/docker/volumes# docker volume lsDRIVER VOLUME NAMElocal 4ad594eee4e6115b2852f5fa952176c799e99bf1d0cadaee9c581085b8e38b6elocal d309f4a3ce1aa585673548ed4fd43a3aa7a5ca4f86a5a52b236d02428b991379-Anonymous mount local xff-nginx- -how to mount a named root@hecs-39042:/var/lib/docker/volumes## to determine whether it is named, Anonymous, specified path mount-v xff-nginx (volume name): container path-v container path-v / path (host path): / path expansion within container:-v: / path within container: ro or rw# ro can only be operated through host The inside of the container is inoperable!

Data sharing among multiple containers

#-volumes-form implements configuration transfer between containers. The life cycle of the data volume container lasts until no container is used. Once persisted (mounted) to the local, even if the image is deleted, the local data will not delete docker run-d-P-name nginx01 nginxdocker run-d-P-name nginx02-- volumes-form nginx01 nginxdocker run-d-P-name nginx03-- volumes-form nginx01 nginx first met Dockerfile commit.

Dockerfile is used to build images, command parameter scripts.

Build steps:

1. Write a dockerfile

2.docker build is built into a mirror image

3.docker run runs the image

4.docker push publish Image

# basic image mount directory command: uppercase FROM ubuntuVOLUME ["volume01", "volume02"] CMD echo "- build image succeed----" CMD / bin/bashDockerfile construction process

1. Each keyword must be an uppercase letter

two。 Execution order from top to bottom

3.# indicates comments

4. Each instruction creates a new image to submit and submits it

Command

FROM # basic image MAINTAINER # image who released, name + mailbox RUN # image construction command ADD # step: tomcat image, this tomcat package Add content WORKDIR # the working directory of the image VOLUME # mount the host directory EXPOSE # specify the external port CMD # specify the command to run when the container starts, only the last command will take effect ENTRPOINT # specify the command to run when the container starts, you can append the command ONBUILD # to build an inherited Dockerfile and then run COPY # similar to ADD Copy the file to the image ENV # set the environment variable when building

Create a ubuntu

The difference between CMD and ENTRYPOINT

Root@hecs-39042:/home/docker# docker run ubuntu-cmd-ldocker: Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "- l": executable file not found in $PATH: unknown.root@hecs-39042:/home/docker#root@hecs-39042:/home/docker# docker run ubuntu-entrypoint-l-itotal 56drwxr-xr-x 1 root root 4096 Mar 27 07:13. Drwxr-xr-x 1 root root 4096 Mar 27 07:13.-rwxr-xr-x 1 root root 0 Mar 27 07:13. The external incoming command of the dockerenvCMD will overwrite the ENTRYPOINT in the dockerfile. Parameters can be appended by external commands.

Write a Dockerfile

Publish an image

Start the container

Publish your own image

Docker login

Docker Network veth-pair-- link

Custom network

Docker run-d-P-- name tomcat06-- net bridge tomcatdocker0 features: cannot be accessed through a domain name -- link can get through # create custom network docker network create-- driver bridge-- subnet 192.168.0 mynet# 16-- gateway 192.168.0.1 mynet# launch container specify custom network docker run-d-P-- name tomcat-mynet-01-- net mynet tomcat # Cross-network operation container docker network connect mynet contain thank you for reading this article carefully I hope the article "what are the basic docker commands" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

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