Docker installation and sharing of common commands and sharing of common docker commands

Source: Internet
Author: User
Tags docker ps apache tomcat cloudbees dwolla

Docker installation and sharing of common commands and sharing of common docker commands

Basic commands

1. To install docker in yum, the root permission is required.

Yum install docker

2. Start docker

Systemctl start docker. service

3. view the docker status

Systemctl status docker. service

4. Add boot items

Systemctl enable doccker. service

5. Get the centos image. The download time is related to the network. It may take a long time!

Docker pull centos: latest

7. view images (locally mounted images)

Docker images centos

8. Run bash to run simple test cases!

Docker run-I-t centos/bin/bash

9. Check whether the installation is successful.

$ Docker version

10. Verify that docker is successfully installed.

Docker info

11. view the docker Process

Systemctl | grep docker

12. Disable the Firewall

Systemctl disables firewall

13. If no network environment is required, install iptables to map ports.

Yum install iptables-services

Systemctl enable iptables

Systemctl start iptables

14. Check ip address a after startup and find that a docker0 (BRIDGE) is allocated)

Docker0: mtu 1500 qdisc noqueue state DOWN

Link/ether 02: 42: cc: f6: 67: 93 brd ff: ff

Inet 172.17.0.1/16 scope global docker0

Valid_lft forever preferred_lft forever

15. View logs (for troubleshooting)

Tail-f/var/log/messages | grep docker

16. Basic commands

Docker search

Docker pull java

Docker images

Docker run-it java-version (-it Interaction Mode)

Docker run-it java ps

Docker run-it java uname

Docker run java ip addr

Docker run java env

The command in docker run is over, and the container is over.

Docker run [options] IMAGE [: TAG] [COMAND] [ARG ..]

Determines the container running mode, whether it is executed in the foreground or in the background.

Append-d = true or-d after docker run, the container will run in background mode.

Docker exec to enter the container, or attach to reconnect to the container.

For interactive operations (such as shell), we must use the-I-t parameter to interact with the container data.

-- Name is not specified during docker run, deamon will automatically generate a random string UUID

Docker has automatic requirements. You can output containerID to the specified file (PIDfile): -- cidfile =''

Docker containers have no privileges. For example, you cannot start another container in the container. This is because the container cannot access any other device by default, but through "privileged ", the container has the permission to access any other device.

==========================================

Instance

Root @ ip-10-249-100-205 ~] # Yum install docker

Loaded plugins: fastestmirror

Repodata is over 2 weeks old. Install yum-cron Or run: yum makecache fast

Base | 3.6 kB 00:00:00

Epel | 4.7 kB 00:00:00

Extras | 3.4 kB 00:00:00

Updates | 3.4 kB 00:00:00

(1/5): epel/x86_64/updateinfo | 880 kB 00:00:00

(2/5): epel/x86_64/group_gz | 266 kB 00:00:00

(3/5): extras/7/x86_64/primary_db | 166 kB 00:00:00

(4/5): epel/x86_64/primary_db | 6.2 MB 00:00:00

(5/5): updates/7/x86_64/primary_db | 6.0 MB 00:00:01

Determining fastest mirrors

* Base: mirrors.aliyun.com

* Epel: mirrors.aliyun.com

* Extras: mirrors.aliyun.com

.................

[Root @ ip-10-249-100-205 ~] # Systemctl status docker. service

● Docker. service-Docker Application Container Engine

Loaded: loaded (/usr/lib/systemd/system/docker. service; disabled; vendor preset: disabled)

Active: inactive (dead)

Docs: http://docs.docker.com

[Root @ ip-10-249-100-205 ~] # Systemctl start docker. service

[Root @ ip-10-249-100-205 ~] # Systemctl status docker. service

● Docker. service-Docker Application Container Engine

Loaded: loaded (/usr/lib/systemd/system/docker. service; disabled; vendor preset: disabled)

Active: active (running) since Thu 2012-02-08 16:01:18 CST; 2 s ago

Docs: http://docs.docker.com

Main PID: 3066 (dockerd-current)

CGroup:/system. slice/docker. service

Container-3066/usr/bin/dockerd-current -- add-runtime docker-runc =/usr/libexec/docker-runc-current -- default-runtime = do...

Container-3073/usr/bin/docker-containerd-current-l unix: // var/run/docker/libcontainerd/docker-containerd.sock -- shim docker...

Feb 08 16:01:17 ip-10-249-100-205 dockerd-current [3066]: time = "2018-02-08T16: 01: 17.910795663 + 08: 00" level = warning msg = "mount... ound"

Feb 08 16:01:17 ip-10-249-100-205 dockerd-current [3066]: time = "2018-02-08T16: 01: 17.911051246 + 08: 00" level = info msg = "Loading... art ."

Feb 08 16:01:17 ip-10-249-100-205 dockerd-current [3066]: time = "2018-02-08T16: 01: 17.949714902 + 08: 00" level = warning msg = "Running mo...

Feb 08 16:01:17 ip-10-249-100-205 dockerd-current [3066]: time = "2018-02-08T16: 01: 17.993634012 + 08: 00" level = info msg = "Firewall... alse"

Feb 08 16:01:18 ip-10-249-100-205 dockerd-current [3066]: time = "2018-02-08T16: 01: 18.211764057 + 08: 00" level = info msg = "Default... ress"

Feb 08 16:01:18 ip-10-249-100-205 dockerd-current [3066]: time = "2018-02-08T16: 01: 18.346131674 + 08: 00" level = info msg = "Loading... one ."

Feb 08 16:01:18 ip-10-249-100-205 dockerd-current [3066]: time = "2018-02-08T16: 01: 18.346247481 + 08: 00" level = info msg = "Daemon h... tion"

Feb 08 16:01:18 ip-10-249-100-205 dockerd-current [3066]: time = "2018-02-08T16: 01: 18.346270371 + 08: 00" level = info msg = "Docker d... 12.6

Feb 08 16:01:18 ip-10-249-100-205 dockerd-current [3066]: time = "2018-02-08T16: 01: 18.353981494 + 08: 00" level = info msg = "API list... sock"

Feb 08 16:01:18 ip-10-249-100-205 systemd [1]: Started Docker Application Container Engine.

Hint: Some lines were ellipsized, use-l to show in full.

[Root @ ip-10-249-100-205 ~] # Systemctl enable docker. service

Created symlink from/etc/systemd/system/multi-user.target.wants/docker. service to/usr/lib/systemd/system/docker. service.

[Root @ ip-10-249-100-205 ~] # Systemctl | grep docker

Sys-devices-virtual-net-docker0.device loaded active plugged/sys/devices/virtual/net/docker0

Sys-subsystem-net-devices-docker0.device loaded active plugged/sys/subsystem/net/devices/docker0

● Docker-storage-setup.service loaded failed Docker Storage Setup

Docker. service loaded active running Docker Application Container Engine

Docker-cleanup.timer loaded active waiting Run docker-cleanup every hour

[Root @ ip-10-249-100-205 ~] # Docker version

Client:

Version: 1.12.6

API version: 1.24

Package version: docker-1.12.6-71.git3e8e77d.el7.centos.1.x86_64

Go version: go1.8.3

Git commit: 3e8e77d/1.12.6

Built: Tue Jan 30 09:17:00 2018

OS/Arch: linux/amd64

Server:

Version: 1.12.6

API version: 1.24

Package version: docker-1.12.6-71.git3e8e77d.el7.centos.1.x86_64

Go version: go1.8.3

Git commit: 3e8e77d/1.12.6

Built: Tue Jan 30 09:17:00 2018

OS/Arch: linux/amd64

[Root @ ip-10-249-100-205 ~] # Docker info

Containers: 0

Running: 0

Paused: 0

Stopped: 0

Images: 0

Server Version: 1.12.6

Storage Driver: devicemapper

Pool Name: docker-253: 0-201736978-pool

Pool Blocksize: 65.54 kB

Base Device Size: 10.74 GB

Backing Filesystem: xfs

Data file:/dev/loop0

Metadata file:/dev/loop1

Data Space Used: 11.8 MB

Data Space Total: 107.4 GB

Data Space Available: 47.4 GB

Metadata Space Used: 581.6 kB

Metadata Space Total: 2.147 GB

Metadata Space Available: 2.147 GB

Thin Pool Minimum Free Space: 10.74 GB

Udev Sync Supported: true

Deferred Removal Enabled: true

Deferred Deletion Enabled: true

Deferred Deleted Device Count: 0

Data loop file:/var/lib/docker/devicemapper/data

WARNING: Usage of loopback devices is stronugly discouraged for production use. Use '-- storage-opt dm. thinpooldev' to specify a custom block storage device.

Metadata loop file:/var/lib/docker/devicemapper/metadata

Library Version: 1.02.107-RHEL7 (2015-10-14)

Logging Driver: journald

Cgroup Driver: systemd

Plugins:

Volume: local

Network: null host bridge overlay

Swarm: inactive

Runtimes: docker-runc

Default Runtime: docker-runc

Security Options: seccomp

Kernel Version: 3.10.0-327. el7.x86 _ 64

Operating System: CentOS Linux 7 (Core)

OSType: linux

Architecture: x86_64

Number of Docker Hooks: 3

CPUs: 4

Total Memory: 7.64 GiB

Name: ip-10-249-100-205

ID: PR4W: F4PU: Q6CN: 7WDF: KSRH: BA2D: HYQR: UMDB: OCWT: FE6B: LXKV: MWBK

Docker Root Dir:/var/lib/docker

Debug Mode (client): false

Debug Mode (server): false

Registry: https://index.docker.io/v1/

WARNING: bridge-nf-call-iptables is disabled

WARNING: bridge-nf-call-ip6tables is disabled

Insecure Registries:

127.0.0.0/8

Registries: docker. io (secure)

[Root @ ip-10-249-100-205 ~] #

[Root @ ip-10-249-100-205 ~] # Tail-f/var/log/messages | grep docker

Feb 8 16:01:18 ip-10-249-100-205 nm-dispatcher: Dispatching action 'up' for docker0

Feb 8 16:01:18 ip-10-249-100-205 dockerd-current: time = "2018-02-08T16: 01: 18.346131674 + 08: 00" level = info msg = "Loading containers: done ."

Feb 8 16:01:18 ip-10-249-100-205 dockerd-current: time = "2018-02-08T16: 01: 18.346247481 + 08: 00" level = info msg = "Daemon has completed initialization"

Feb 8 16:01:18 ip-10-249-100-205 dockerd-current: time = "2018-02-08T16: 01: 18.346270371 + 08: 00 "level = info msg =" Docker daemon "commit =" 3e8e77d/1.12.6 "graphdriver = devicemapper version = 1.12.6

Feb 8 16:01:18 ip-10-249-100-205 dockerd-current: time = "2018-02-08T16: 01: 18.353981494 + 08: 00" level = info msg = "API listen on/var/run/docker. sock"

[Root @ ip-10-249-100-205 ~] # Docker search java

Index name description stars official automatic

Docker. io docker. io/node Node. js is a JavaScript-based platform for... 5078 [OK]

Docker. io docker. io/tomcat Apache Tomcat is an open source implementa... 1713 [OK]

Docker. io docker. io/java Java is a concurrent, class-based, and obj... 1633 [OK]

Docker. io docker. io/openjdk OpenJDK is an open-source implementation o... 822 [OK]

Docker. io docker. io/ghost Ghost is a free and open source blogging p... 704 [OK]

Docker. io docker. io/anapsix/alpine-java Oracle Java 8 (and 7) with GLIBC 2.23 over... 280 [OK]

Docker. io docker. io/jetty Jetty provides a Web server and javax. serv... 225 [OK]

Docker. io docker. io/isuper/java-oracle This repository contains all java releases... 55 [OK]

Docker. io docker. io/lwieske/java-8 Oracle Java 8 Container-Full + Slim-Ba... 37 [OK]

Docker. io docker. io/groovy Apache Groovy is a multi-faceted language... 27 [OK]

Docker. io docker. io/cloudbees/jnlp-slave-with-java-build-tools Extends cloudbees/java-build-tools docker... 15 [OK]

Docker. io docker. io/zabbix-java-gateway Zabbix Java Gateway 9 [OK]

Docker. io docker. io/blacklabelops/java Oracle Java Base Images. Alpine and CentOS... 8 [OK]

Docker. io docker. io/frekele/java docker run -- rm -- name java frekele/java 7 [OK]

Docker. io docker. io/1 science/java Java Docker images based on Alpine Linux 6 [OK]

Docker. io docker. io/David caste/alpine-java-unlimited-jce Oracle Java 8 (and 7) with GLIBC 2.21 over... 6 [OK]

Docker. io docker. io/fabric8/s2i-java S2I Builder Image for plain Java applications 3

Docker. io docker. io/dwolla/java Dwolla's custom Java image 1 [OK]

Docker. io docker. io/appuio/s2i-gradle-java S2I Builder with Gradle and Java 0 [OK]

Docker. io docker. io/appuio/s2i-maven-java S2I Builder with Maven and Java 0 [OK]

Docker. io docker. io/appuio/s2i-play-java Simple S2I Builder Image for Play and Java 0 [OK]

Docker. io docker. io/cfje/java-buildpack Java Buildpack CI Image 0

Docker. io docker. io/cfje/java-test-applications Java Test Applications CI Image 0

Docker. io docker. io/pcfcodesigning/code-signing-java-phantom Base Java image with PhantomJS 2.1.1 0

Docker. io docker. io/thingswise/java-docker Java + dcd 0 [OK]

[Root @ ip-10-249-100-205 ~] # Docker images

REPOSITORY TAG IMAGE ID CREATED SIZE

Docker. io/java latest d23bdf5b1b1b 12 months ago 643.1 MB

[Root @ ip-10-249-100-205 ~] # Docker run-it java-version

Open JDK version "1.8.0 _ 111"

OpenJDK Runtime Environment (build 1.8.0 _ 111-8u111-b14-2 ~ Bpo8 + 1-b14)

OpenJDK 64-Bit Server VM (build 25.111-b14, mixed mode)

[Root @ ip-10-249-100-205 ~] # Docker run-it java ps

PID TTY TIME CMD

00:00:00 ps

[Root @ ip-10-249-100-205 ~] # Docker run-it java uname

Linux

[Root @ ip-10-249-100-205 ~] # Docker run java ip addr

1: lo: mtu 65536 qdisc noqueue state UNKNOWN group default

Link/loopback 00: 00: 00: 00: 00: 00 brd 00: 00: 00: 00: 00: 00

Inet 127.0.0.1/8 scope host lo

Valid_lft forever preferred_lft forever

Inet6: 1/128 scope host

Valid_lft forever preferred_lft forever

10: eth0 @ if11: mtu 1500 qdisc noqueue state UP group default

Link/ether 02: 42: ac: 11: 00: 02 brd ff: ff

Inet 172.17.0.2/16 scope global eth0

Valid_lft forever preferred_lft forever

Inet6 fe80 ::42: acff: fe11: 2/64 scope link tentative

Valid_lft forever preferred_lft forever

[Root @ ip-10-249-100-205 ~] # Docker run java env

PATH =/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

HOSTNAME = 0d4a117ad942

LANG = C.UTF-8

JAVA_HOME =/usr/lib/jvm/java-8-openjdk-amd64

JAVA_VERSION = 8u111

JAVA_DEBIAN_VERSION = 8u111-b14-2 ~ Bpo8 + 1

CA_CERTIFICATES_JAVA_VERSION = 20140324

HOME =/root

[Root @ ip-10-249-100-205 ~] #

========================================================== ====

17. Container lifecycle instructions

Docker create/start/stop/pause/unpause

Create only creates a container and does not start

Docker create-it -- name = myjava java-version

Docker start myjava

Download a mysql image and set the user name and password

Docker create -- name mysqlsrv1-e MYSQL_ROOT_PASSWORD = 123456-p 3306: 3306 mysql

Docker start mysqlsrv1

Docker ps

Install a client. You can log on

Docker exec-it mysqlsrv1/bin/bash enter container Interaction Mode

Root @ 1549052941a1:/# cat/var/log/mysql/error. log

Root @ 1549052941a1:/# env

HOSTNAME = 1549052941a1

MYSQL_VERSION = 5.7.21-1debian8

PATH =/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

PWD =/

SHLVL = 1

HOME =/root

MYSQL_MAJOR = 5.7

GOSU_VERSION = 1.7

MYSQL_ROOT_PASSWORD = 123456

_ =/Usr/bin/env

======================================

[Root @ ip-10-249-100-205 ~] # Docker create-it -- name = myjava java-version

Bytes

[Root @ ip-10-249-100-205 ~] # Docker ps-

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

195b0223db4a java "java-version" 6 seconds ago Created myjava

0d4a117ad942 java "env" 2 minutes ago Exited (0) 2 minutes ago lonely_boyd

F9770dd1783e java "ip addr" 2 minutes ago Exited (0) 2 minutes ago focused_volhard

15af6702edf0 java "uname" 2 minutes ago Exited (0) 2 minutes ago prickly_curie

6a80c6413d52 java "ps" 2 minutes ago Exited (0) 2 minutes ago distracted_noether

5dead85d580b java "java-version" 3 minutes ago Exited (0) 3 minutes ago fervent_northcutt

[Root @ ip-10-249-100-205 ~] #

[Root @ ip-10-249-100-205 ~] # Docker start myjava

Myjava

[Root @ ip-10-249-100-205 ~] # Docker ps front-end execution is complete, and the back-end is no longer available

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[Root @ ip-10-249-100-205 ~] #

[Root @ ip-10-249-100-205 ~] # Docker create -- name mysqlsrv1-e MYSQL_ROOT_PASSWORD = 123456-p 3306: 3306 mysql

Unable to find image 'mysql: latest 'locally

Trying to pull repository docker. io/library/mysql...

Latest: Pulling from docker. io/library/mysql

F49cf87b52c1: Pull complete

78032de49d65: Pull complete

837546b20bc4: Pull complete

9b8da-af6cc6: Pull complete

1056cf29b9f1: Pull complete

86f3913b029a: Pull complete

F98eea8321ca: Pull complete

3a8e3ebdeaf5: Pull complete

4be06ac1c51e: Pull complete

920c7ffb7747: Pull complete

Digest: sha256: 7cdb08f30a54d417ddded59525937592cb6852ff635a546626a8960d9ec34c30

Bytes

[Root @ ip-10-249-100-205 ~] # Docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

[Root @ ip-10-249-100-205 ~] # Docker start mysqlsrv1

Mysqlsrv1

[Root @ ip-10-249-100-205 ~] # Docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

1549052941a1 mysql "docker-entrypoint.sh" 2 minutes ago Up 1 seconds 0.0.0.0: 3306-> 3306/tcp mysqlsrv1

[Root @ ip-10-249-100-205 ~] # Netstat-tlp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

Tcp 0 0 0.0.0.0: ssh 0.0.0.0: * LISTEN 892/sshd

Tcp 0 0 localhost: smtp 0.0.0.0: * LISTEN 1858/master

Tcp6 0 0 [:]: mysql [:]: * LISTEN 4649/docker-proxy-c

Tcp6 0 0 [:]: http [:]: * LISTEN 23859/java

Tcp6 0 0 [:]: ssh [:]: * LISTEN 892/sshd

Tcp6 0 0 localhost: smtp [:]: * LISTEN 1858/master

Tcp6 0 0 [:]: 19295 [:]: * LISTEN 23859/java

Tcp6 0 0 localhost: 10501 [:]: * LISTEN 23859/java

[Root @ ip-10-249-100-205 ~] # Yum install mysql

[Root @ ip-10-249-100-205 ~] # Mysql-uroot-p123456-h10.249.100.205

Welcome to the MariaDB monitor. Commands end with; or \ g.

Your MySQL connection id is 2

Server version: 5.7.21 MySQL Community Server (GPL)

Copyright (c) 2000,201 7, Oracle, MariaDB Corporation AB and others.

Type 'help; 'or' \ H' for help. type' \ C' to clear the current input statement.

MySQL [(none)]>

18. Process Management

When the Docker container exits, the file system inside the container is retained by default to facilitate debugging and retain user data.

However, for the foreground container, because it only runs for a short period of time during development and debugging, its user data is not necessary to be retained. Therefore, you can set the -- rm option when the container is started, in this way, the file system inside the container can be automatically cleaned up when the container exits.

[Root @ ip-10-249-100-205 ~] # Docker ps

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

1549052941a1 mysql "docker-entrypoint.sh" 23 minutes ago Up 20 minutes 0.0.0.0: 3306-> 3306/tcp mysqlsrv1

[Root @ ip-10-249-100-205 ~] # Docker ps-

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

1549052941a1 mysql "docker-entrypoint.sh" 23 minutes ago Up 20 minutes 0.0.0.0: 3306-> 3306/tcp mysqlsrv1

195b0223db4a java "java-version" 34 minutes ago Exited (0) 33 minutes ago myjava

0d4a117ad942 java "env" 36 minutes ago Exited (0) 36 minutes ago lonely_boyd

F9770dd1783e java "ip addr" 36 minutes ago Exited (0) 36 minutes ago focused_volhard

15af6702edf0 java "uname" 37 minutes ago Exited (0) 37 minutes ago prickly_curie

6a80c6413d52 java "ps" 37 minutes ago Exited (0) 37 minutes ago distracted_noether

5dead85d580b java "java-version" 37 minutes ago Exited (0) 37 minutes ago fervent_northcutt

The above shows that both the running docker and the running docker exist, and the disk space will be used temporarily.

Run-rm needs to be added

Docker run -- rm java ps

Docker run -- rm-it java ps

Obviously, the -- rm option cannot be used with-d at the same time, that is, the foreground container can only be automatically cleared, and the detached container cannot be automatically cleared.

Note that the -- rm option also clears the container's anonymous data volumes.

Therefore, executing the docker run command with the -- rm command option is equivalent to executing docker rm-v after the container exits.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.