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 operating methods of Docker

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly explains "what are the basic operating methods of Docker". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the basic operating methods of Docker"?

Install Dockerroot@jaking-virtual-machine:~# apt-get install-y docker-engineReading package lists... DoneBuilding dependency tree Reading state information... Done...root@jaking-virtual-machine:~# docker versionClient:Version: 18.06.1-ceAPI version: 1.38Go version: go1.10.4Git commit: e68fc7aBuilt: Fri Oct 19 19:43:14 2018OS/Arch: linux/amd64Experimental: falseServer:Engine: Version: 18.06.1-ceAPI version: 1.38 (minimum version 1. 12) Go version: go1.10.4 Git commit: e68fc7a Built: Thu Sep 27 02:39:50 2018 OS/Arch: linux/amd64 Experimental: falseroot@jaking-virtual-machine:~# systemctl start dockerroot@jaking-virtual-machine:~# systemctl enable dockerSynchronizing state of docker.service with SysV service script with / lib/systemd/systemd-sysv-install.Executing: / lib/systemd/systemd-sysv-install enable docker

Search for ubuntu-related containers

Root@jaking-virtual-machine:~# docker search ubuntuNAME DESCRIPTION STARS OFFICIAL AUTOMATEDubuntu Ubuntu is a Debian-based Linux operating sys... 8838 [OK] dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 247 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi... [OK] consol/ubuntu-xfce-vnc Ubuntu container with "headless" VNC session... 136 [OK] ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 95 [OK] ubuntu-upstart Upstart is an event-based replacement for th... 92 [OK] download container root@jaking-virtual-machine:~# docker pull ubuntu-upstartUsing default tag: latestlatest: Pulling from library/ubuntu-upstart8387d9ff0016: Pull complete3b52deaaf0ed: Pull complete4bd501fad6de: Pull completea3ed95caeb02: Pull completea6dc1658c730: Pull complete9ed623dca71b: Pull complete998ee72febf9: Pull complete437038dc2fba: Pull completeda0ee05a1a1d: Pull complete1e1c3e99deb1: Pull complete4fcc22d7b2a1: Pull complete6c7dda5571e4: Pull completeDigest: sha256:597dfb1868012dcd04a705572dbc1542cb7598bce0eaa1c2656eb3acfc8b51d2Status: Downloaded newer image for ubuntu-upstart:latest to view the container's image root@jaking-virtual-machine:~# docker images ubuntu-upstartREPOSITORY TAG IMAGE ID CREATED SIZEubuntu-upstart latest b28219773b9b 2 years ago 253MB

As you can see from the above results, the container has been downloaded successfully. Using the downloaded ubuntu-upstart container, you can run a simple program, taking "Hello Docker" as an example:

Root@jaking-virtual-machine:~# docker run ubuntu-upstart / bin/echo Hello DockerHello Docker

You can also use other containers, such as using ubuntu as a container. Download operations are as follows:

Container operation of root@jaking-virtual-machine:~# docker pull ubuntuUsing default tag: latestlatest: Pulling from library/ubuntu32802c0cfa4d: Pull completeda1315cffa03: Pull completefa83472a3562: Pull completef85999a86bef: Pull completeDigest: sha256:6d0e0c26489e33f5a6f0020edface2727db9489744ecc9b4f50c7fa671f23c49Status: Downloaded newer image for ubuntu:latestroot@jaking-virtual-machine:~# docker images ubuntuREPOSITORY TAG IMAGE ID CREATED SIZEubuntu latest 93fd78260bd1 10 days ago 86.2MBDocker

When the container is included in the Docker, just like the operating system is installed in the virtual machine, you can run, install the software, and make some settings. You can now run the ubuntu you downloaded earlier:

Root@jaking-virtual-machine:~# docker run-I-t ubuntu / bin/bash# runs a container called ubuntu # I option to capture standard input and output The t option indicates that the assigned terminal and console root@05559b460591:/#root@05559b460591:/# uname-aLinux 05559b460591 4.15.0-36-generic # 39-Ubuntu SMP Mon Sep 24 16:19:09 UTC 2018 x86 "64 GNU/Linuxroot@05559b460591:/# exit# exit container exitroot@jaking-virtual-machine:~# docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

The command can see that a container was run with the run command, but the container was closed after exiting, which is not the desired result-you can use option d to keep the container running "data-source-line=" 114s in the background. > as you can see from the command above, a container is run with the run command, but the container is also closed after exit, which is not the desired result. You can use option d to keep the container running in the background:

Root@jaking-virtual-machine:~# docker run-d-I-t ubuntu / bin/bashb19cc95aef9cb6f402062915b527864cf045debc65dbabd23a495cea32a138ddroot@jaking-virtual-machine:~# docker ps-aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESb19cc95aef9c ubuntu "/ bin/bash" 15 seconds ago Up 14 seconds Kind_johnson05559b460591 ubuntu "/ bin/bash" 35 minutes ago Exited (0) 9 minutes ago xenodochial_hypatia5bc78fd29b2a ubuntu-upstart "/ bin/echo Hello Doc …" 42 minutes ago Exited (0) 42 minutes ago silly_jenningsc54bb6d664b7 ubuntu-upstart "/ bin/echo Hello Doc …" 44 minutes ago Exited (0) 44 minutes ago jolly_thompson

From the above command output, you can see that a container with an ID of b19cc95aef9c is running, and the ID number is an important parameter for manipulating the container. When the container is running in the background, you can use attach to log in to the running container:

Root@jaking-virtual-machine:~# docker attach b19cc95aef9croot@b19cc95aef9c:/# exitexitroot@jaking-virtual-machine:~#

There are many commands for container operations, and common operations include:

Docker cp: copy the files in the container to the host docker rm: delete a container docker port: configure container port forwarding docker start: start a container docker stop: stop a container docker top: display the processes in the container docker ps: list the container docker logs: get the container log in addition to the above operations, Docker has many operations, you can read the relevant documents to understand. Thank you for your reading, these are the contents of "what are the basic methods of operation of Docker". After the study of this article, I believe you have a deeper understanding of the basic methods of operation of Docker, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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