26 Most Common Docker Commands with Examples

Docker command cheat sheet for sysadmin and builders…

Docker is a containerization system that packages and runs the applying with its dependencies in a container. There are a number of docker instructions it is best to know when working with Docker. This text is all about that.

If you do not know what Docker is, you may take this Udemy newbie course.

Discovering the model

One of many first stuff you’ll wish to know is tips on how to discover the docker model put in.

geekflare@bestnich:/residence/geekflare$ docker --version

Docker model 18.09.6, construct 481bc77

Obtain picture

Say it is advisable get the docker picture from dockerhub (docker repository). The next instance of getting the Apache HTTP server picture.

geekflare@bestnich:/residence/geekflare$ docker pull httpd

Utilizing default tag: newest

newest: Pulling from library/httpd

f5d23c7fed46: Pull full

b083c5fd185b: Pull full

bf5100a89e78: Pull full

98f47fcaa52f: Pull full

622a9dd8cfed: Pull full

Digest: sha256:8bd76c050761610773b484e411612a31f299dbf7273763103edbda82acd73642

Standing: Downloaded newer picture for httpd:newest

geekflare@bestnich:/residence/geekflare$

Footage

Listing all docker pictures retrieved on the system with picture particulars like TAG/IMAGE ID/SIZE and many others.

geekflare@bestnich:/residence/geekflare$ docker pictures

REPOSITORY                 TAG                 IMAGE ID            CREATED             SIZE

httpd                      newest              ee39f68eb241        2 days in the past          154MB

hello-world                newest              fce289e99eb9        6 months in the past        1.84kB

sequenceiq/hadoop-docker   2.7.0               789fa0a3b911        4 years in the past         1.76GB

Stroll

Run the docker picture listed within the command. This command creates a docker container by which the Apache HTTP server will run.

geekflare@bestnich:/residence/geekflare$ docker run -it -d httpd

09ca6feb6efc0578951a3e2557ed5855b2edda39a795d9703eb54d975930fe6e

What’s going on?

ps lists all docker containers working with container particulars.

geekflare@bestnich:/residence/geekflare$ docker ps

CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS               NAMES

09ca6feb6efc        httpd               "httpd-foreground"   36 seconds in the past      Up 33 seconds       80/tcp              suspicious_bell

As you may see, the Apache server runs on this docker container.

ps-a

Listing all docker containers working/deserted/stopped with container knowledge.

geekflare@bestnich:/residence/geekflare$ docker ps -a

CONTAINER ID        IMAGE                            COMMAND                  CREATED             STATUS                     PORTS                                                                                                                                NAMES

09ca6feb6efc        httpd                            "httpd-foreground"       51 seconds in the past      Up 49 seconds              80/tcp                                                                                                                               suspicious_bell

2f6fb3381078        sequenceiq/hadoop-docker:2.7.0   "/and many others/bootstrap.sh -d"   2 weeks in the past         Exited (137) 9 days in the past                                                                                                                                         quizzical_raman

9f397feb3a46        sequenceiq/hadoop-docker:2.7.0   "/and many others/bootstrap.sh -…"   2 weeks in the past         Exited (255) 2 weeks in the past   2122/tcp, 8030-8033/tcp, 8040/tcp, 8042/tcp, 8088/tcp, 19888/tcp, 49707/tcp, 50010/tcp, 50020/tcp, 50070/tcp, 50075/tcp, 50090/tcp   determined_ritchie

9b6343d3b5a0        hello-world                      "/good day"                 2 weeks in the past         Exited (0) 2 weeks in the past                                                                                                                                          peaceful_mclean

government

Entry the docker container and run instructions within the container. On this instance, I’m accessing the Apache server container.

geekflare@bestnich:/residence/geekflare$ docker exec -it 09ca6feb6efc bash

root@09ca6feb6efc:/usr/native/apache2# ls

bin  construct  cgi-bin  conf  error  htdocs  icons  embody  logs                modules

root@09ca6feb6efc:/usr/native/apache2#

Sort Exit and press enter to get out of the container.

Take away holder

Delete the docker container with container ID specified within the command.

geekflare@bestnich:/residence/geekflare$ docker rm 9b6343d3b5a0

9b6343d3b5a0

Run the command under to examine whether or not the container has been deleted or not.

geekflare@bestnich:/residence/geekflare$ docker ps -a

CONTAINER ID        IMAGE                            COMMAND                  CREATED              STATUS                     PORTS                                                                                                                                NAMES

09ca6feb6efc        httpd                            "httpd-foreground"       A couple of minute in the past   Up A couple of minute          80/tcp                                                                                                                               suspicious_bell

2f6fb3381078        sequenceiq/hadoop-docker:2.7.0   "/and many others/bootstrap.sh -d"   2 weeks in the past          Exited (137) 9 days in the past                                                                                                                                         quizzical_raman

9f397feb3a46        sequenceiq/hadoop-docker:2.7.0   "/and many others/bootstrap.sh -…"   2 weeks in the past          Exited (255) 2 weeks in the past   2122/tcp, 8030-8033/tcp, 8040/tcp, 8042/tcp, 8088/tcp, 19888/tcp, 49707/tcp, 50010/tcp, 50020/tcp, 50070/tcp, 50075/tcp, 50090/tcp   determined_ritchie

Take away picture

Take away the docker picture with the docker picture ID listed within the command

geekflare@bestnich:/residence/geekflare$ docker rmi fce289e99eb9

Untagged: hello-world:newest

Untagged: hello-world@sha256:41a65640635299bab090f783209c1e3a3f11934cf7756b09cb2f1e02147c6ed8

Deleted: sha256:fce289e99eb9bca977dae136fbe2a82b6b7d4c372474c9235adc1741675f587e

Deleted: sha256:af0b15c8625bb1938f1d7b17081031f649fd14e6b233688eea3c5483994a66a3

geekflare@bestnich:/residence/geekflare$

Restart Docker

Restart the docker container with the container ID specified within the command.

geekflare@bestnich:/residence/geekflare$ docker restart 09ca6feb6efc

09ca6feb6efc

Run the command under and examine the STATUS parameter to confirm if the container has been began just lately.

geekflare@bestnich:/residence/geekflare$ docker ps

CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS               NAMES

09ca6feb6efc        httpd               "httpd-foreground"   6 minutes in the past       Up 9 seconds        80/tcp              suspicious_bell

Cease Docker

Cease a container with container ID specified within the command.

geekflare@bestnich:/residence/geekflare$ docker cease 09ca6feb6efc

09ca6feb6efc

Run the command under to examine if the container remains to be working or stopped.

geekflare@bestnich:/residence/geekflare$ docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

Launch Docker

This docker command launches the docker container with the container ID specified within the command.

geekflare@bestnich:/residence/geekflare$ docker begin 09ca6feb6efc

09ca6feb6efc

Run the command under to examine if the container is began or not.

geekflare@bestnich:/residence/geekflare$ docker ps

CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS               NAMES

09ca6feb6efc        httpd               "httpd-foreground"   8 minutes in the past       Up 3 seconds        80/tcp              suspicious_bell

Kill

Cease the docker container instantly. Docker cease command gracefully stops the container, that is the distinction between a kill and cease command.

geekflare@bestnich:/residence/geekflare$ docker kill 09ca6feb6efc

09ca6feb6efc

Run the command under to see if the container is killed or not.

geekflare@bestnich:/residence/geekflare$ docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

To attach

Save a brand new docker picture with the container ID specified within the command on the native system. Within the instance under, geekflare is the username and httpd_image is the picture identify.

geekflare@bestnich:/residence/geekflare$ docker commit 09ca6feb6efc geekflare/httpd_image

sha256:d1933506f4c1686ab1a1ec601b1a03a17b41decbc21d8acd893db090a09bb31c

Sign up

Log in to docker hub. You can be prompted to your docker hub credentials to login.

geekflare@bestnich:/residence/geekflare$ docker login

Login along with your Docker ID to push and pull pictures from Docker Hub. If you do not have a Docker ID, head over to https://hub.docker.com to create one.

Username: geekflare

Password:

Configure a credential helper to take away this warning. See

https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded

Push

Add a docker picture with the picture identify listed within the command on the docker hub.

geekflare@bestnich:/residence/geekflare$ docker push geekflare/httpd_image

The push refers to repository [docker.io/geekflare/httpd_image]

734d9104a6a2: Pushed

635721fc6973: Mounted from library/httpd

bea448567d6c: Mounted from library/httpd

bfaa5f9c3b51: Mounted from library/httpd

9d542ac296cc: Mounted from library/httpd

d8a33133e477: Mounted from library/httpd

newest: digest: sha256:3904662761df9d76ef04ddfa5cfab764b85e3eedaf10071cfbe2bf77254679ac dimension: 1574

Docker community

The next command in docker lists the small print of all networks within the cluster.

geekflare@bestnich:/residence/geekflare$ docker community ls

NETWORK ID          NAME                DRIVER              SCOPE

85083e766f04        bridge              bridge              native

f51d1f3379e0        host                host                native

5e5d9a192c00        none                null                native

There are a number of different docker community instructions.

geekflare@bestnich:/residence/geekflare$ docker community

Utilization:  docker community COMMAND

Handle networks

Instructions:

join     Join a container to a community

create      Create a community

disconnect  Disconnect a container from a community

examine     Show detailed info on a number of networks

ls          Listing networks

prune       Take away all unused networks

rm          Take away a number of networks

Run 'docker community COMMAND --help' for extra info on a command.

Docker info

Get detailed details about docker put in on the system, together with kernel model, variety of containers and pictures, and many others.

geekflare@bestnich:/residence/geekflare$ docker information

Containers: 3

Working: 1

Paused: 0

Stopped: 2

Photographs: 3

Server Model: 18.09.6

Storage Driver: overlay2

Backing Filesystem: extfs

Helps d_type: true

Native Overlay Diff: true

Logging Driver: json-file

Cgroup Driver: cgroupfs

Plugins:

Quantity: native

Community: bridge host macvlan null overlay

Log: awslogs fluentd gcplogs gelf journald json-file native logentries splunk syslog

Swarm: inactive

Runtimes: runc

Default Runtime: runc

Init Binary: docker-init

containerd model: bb71b10fd8f58240ca47fbb579b9d1028eea7c84

runc model: 2b18fe1d885ee5083ef9f0838fee39b62d653e30

init model: fec3683

Safety Choices:

apparmor

seccomp

Profile: default

Kernel Model: 4.18.0-25-generic

Working System: Ubuntu 18.10

OSType: linux

Structure: x86_64

CPUs: 1

Whole Reminiscence: 4.982GiB

Identify: geekflare

ID: RBCP:YGAP:QG6H:B6XH:JCT2:DTI5:AYJA:M44Z:ETRP:6TO6:OPAY:KLNJ

Docker Root Dir: /var/lib/docker

Debug Mode (consumer): false

Debug Mode (server): false

Username: geekflare

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

Labels:

Experimental: false

Insecure Registries:

127.0.0.0/8

Dwell Restore Enabled: false

Product License: Group Engine

Copy file

Copy a file from a docker container to the native system.

On this instance I copy the httpd.pid file in a docker container with id 09ca6feb6efc to /residence/geekflare/

geekflare@bestnich:/residence/geekflare$ sudo docker cp 09ca6feb6efc:/usr/native/apache2/logs/httpd.pid /residence/geekflare/

[sudo] password for bestnich:

Run the command under to examine whether or not the file has been copied or not.

geekflare@bestnich:/residence/geekflare$ ls

Desktop  Paperwork  instance  examples.desktop  httpd.pid  nginx_new.yml  nginx.yml

Test historical past

Exhibits the historical past of a docker picture with the picture identify specified within the command.

geekflare@bestnich:/residence/geekflare$ docker historical past httpd

IMAGE               CREATED             CREATED BY                                      SIZE                COMMENT

ee39f68eb241        2 days in the past          /bin/sh -c #(nop)  CMD ["httpd-foreground"]     0B

<lacking>           2 days in the past          /bin/sh -c #(nop)  EXPOSE 80                    0B

<lacking>           2 days in the past          /bin/sh -c #(nop) COPY file:c432ff61c4993ecd…   138B

<lacking>           4 days in the past          /bin/sh -c set -eux;   savedAptMark="$(apt-m…   49.1MB

<lacking>           4 days in the past          /bin/sh -c #(nop)  ENV HTTPD_PATCHES=           0B

<lacking>           4 days in the past          /bin/sh -c #(nop)  ENV HTTPD_SHA256=b4ca9d05…   0B

<lacking>           4 days in the past          /bin/sh -c #(nop)  ENV HTTPD_VERSION=2.4.39     0B

<lacking>           4 days in the past          /bin/sh -c set -eux;  apt-get replace;  apt-g…   35.4MB

<lacking>           4 days in the past          /bin/sh -c #(nop) WORKDIR /usr/native/apache2    0B

<lacking>           4 days in the past          /bin/sh -c mkdir -p "$HTTPD_PREFIX"  && chow…   0B

<lacking>           4 days in the past          /bin/sh -c #(nop)  ENV PATH=/usr/native/apach…   0B

<lacking>           4 days in the past          /bin/sh -c #(nop)  ENV HTTPD_PREFIX=/usr/loc…   0B

<lacking>           5 days in the past          /bin/sh -c #(nop)  CMD ["bash"]                 0B

<lacking>           5 days in the past          /bin/sh -c #(nop) ADD file:71ac26257198ecf6a…   69.2MB

Test logs

Present the docker container logs with the ID talked about within the command.

geekflare@bestnich:/residence/geekflare$ docker logs 09ca6feb6efc

AH00558: httpd: Couldn't reliably decide the server's totally certified area identify, utilizing 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

AH00558: httpd: Couldn't reliably decide the server's totally certified area identify, utilizing 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

[Mon Jul 15 14:01:55.400472 2019] [mpm_event:notice] [pid 1:tid 140299791516800] AH00489: Apache/2.4.39 (Unix) configured -- resuming regular operations

[Mon Jul 15 14:01:55.400615 2019] [core:notice] [pid 1:tid 140299791516800] AH00094: Command line: 'httpd -D FOREGROUND'

[Mon Jul 15 14:08:36.798229 2019] [mpm_event:notice] [pid 1:tid 140299791516800] AH00491: caught SIGTERM, shutting down

AH00558: httpd: Couldn't reliably decide the server's totally certified area identify, utilizing 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

AH00558: httpd: Couldn't reliably decide the server's totally certified area identify, utilizing 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

[Mon Jul 15 14:08:38.259870 2019] [mpm_event:notice] [pid 1:tid 139974087980160] AH00489: Apache/2.4.39 (Unix) configured -- resuming regular operations

[Mon Jul 15 14:08:38.260007 2019] [core:notice] [pid 1:tid 139974087980160] AH00094: Command line: 'httpd -D FOREGROUND'

[Mon Jul 15 14:09:01.540647 2019] [mpm_event:notice] [pid 1:tid 139974087980160] AH00491: caught SIGTERM, shutting down

AH00558: httpd: Couldn't reliably decide the server's totally certified area identify, utilizing 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

AH00558: httpd: Couldn't reliably decide the server's totally certified area identify, utilizing 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

[Mon Jul 15 14:10:43.782606 2019] [mpm_event:notice] [pid 1:tid 140281554879616] AH00489: Apache/2.4.39 (Unix) configured -- resuming regular operations

[Mon Jul 15 14:10:43.782737 2019] [core:notice] [pid 1:tid 140281554879616] AH00094: Command line: 'httpd -D FOREGROUND'

AH00558: httpd: Couldn't reliably decide the server's totally certified area identify, utilizing 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

AH00558: httpd: Couldn't reliably decide the server's totally certified area identify, utilizing 172.17.0.2. Set the 'ServerName' directive globally to suppress this message

[Mon Jul 15 14:14:08.270906 2019] [mpm_event:notice] [pid 1:tid 140595254346880] AH00489: Apache/2.4.39 (Unix) configured -- resuming regular operations

[Mon Jul 15 14:14:08.272628 2019] [core:notice] [pid 1:tid 140595254346880] AH00094: Command line: 'httpd -D FOREGROUND'

Picture search

Seek for a docker picture on dockerhub with the identify given within the command.

geekflare@bestnich:/residence/geekflare$ docker search hadoop

NAME                             DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED

sequenceiq/hadoop-docker         A straightforward method to strive Hadoop                       611                                     [OK]

uhopper/hadoop                   Base Hadoop picture with dynamic configuration…   98                                      [OK]

harisekhon/hadoop                Apache Hadoop (HDFS + Yarn, tags 2.2 - 2.8)     54                                      [OK]

bde2020/hadoop-namenode          Hadoop namenode of a hadoop cluster             22                                      [OK]

kiwenlau/hadoop                  Run Hadoop Cluster in Docker Containers         19

izone/hadoop                     Hadoop 2.8.5 Ecosystem totally distributed, Ju…   14                                      [OK]

uhopper/hadoop-namenode          Hadoop namenode                                 9                                       [OK]

bde2020/hadoop-datanode          Hadoop datanode of a hadoop cluster             9                                       [OK]

singularities/hadoop             Apache Hadoop                                   8                                       [OK]

uhopper/hadoop-datanode          Hadoop datanode                                 7                                       [OK]

harisekhon/hadoop-dev            Apache Hadoop (HDFS + Yarn) + Dev Instruments + Gi…   6                                       [OK]

Replace configuration

Replace container configurations. All replace choices are displayed right here.

geekflare@bestnich:/residence/geekflare$ docker replace --help

Utilization:  docker replace [OPTIONS] CONTAINER [CONTAINER...]

Replace configuration of a number of containers

Choices:

--blkio-weight uint16        Block IO (relative weight), between 10 and 1000, or 0 to disable

(default 0)

--cpu-period int             Restrict CPU CFS (Utterly Truthful Scheduler) interval

--cpu-quota int              Restrict CPU CFS (Utterly Truthful Scheduler) quota

--cpu-rt-period int          Restrict the CPU real-time interval in microseconds

--cpu-rt-runtime int         Restrict the CPU real-time runtime in microseconds

-c, --cpu-shares int             CPU shares (relative weight)

--cpus decimal               Variety of CPUs

--cpuset-cpus string         CPUs by which to permit execution (0-3, 0,1)

--cpuset-mems string         MEMs by which to permit execution (0-3, 0,1)

--kernel-memory bytes        Kernel reminiscence restrict

-m, --memory bytes               Reminiscence restrict

--memory-reservation bytes   Reminiscence tender restrict

--memory-swap bytes          Swap restrict equal to reminiscence plus swap: '-1' to allow limitless swap

--restart string             Restart coverage to use when a container exits

Run the command under to replace the docker container CPU configuration with the container ID listed within the command.

geekflare@bestnich:/residence/geekflare$ docker replace -c 1 2f6fb3381078

2f6fb3381078

Create quantity

Create a quantity that may use Docker container to retailer knowledge.

geekflare@bestnich:/residence/geekflare$ docker quantity create

7e7bc886f69bb24dbdbf19402e31102a25db91bb29c56cca3ea8b0c611fd9ad0

Run the command under if the quantity is created or not.

geekflare@bestnich:/residence/geekflare$ docker quantity ls

DRIVER              VOLUME NAME

native               7e7bc886f69bb24dbdbf19402e31102a25db91bb29c56cca3ea8b0c611fd9ad0

Set up plugin

Set up a docker plugin vieux/sshfs with debug atmosphere set to 1.

geekflare@bestnich:/residence/geekflare$ docker plugin set up vieux/sshfs DEBUG=1

Plugin "vieux/sshfs" is requesting the next privileges:

- community: [host]

- mount: [/var/lib/docker/plugins/]

- mount: []

- system: [/dev/fuse]

- capabilities: [CAP_SYS_ADMIN]

Do you grant the above permissions? [y/N] y

newest: Pulling from vieux/sshfs

52d435ada6a4: Obtain full

Digest: sha256:1d3c3e42c12138da5ef7873b97f7f32cf99fb6edde75fa4f0bcf9ed277855811

Standing: Downloaded newer picture for vieux/sshfs:newest

Put in plugin vieux/sshfs

Run the under command to checklist the docker plugins.

geekflare@bestnich:/residence/geekflare$ docker plugin ls

ID                  NAME                 DESCRIPTION               ENABLED

2a32d1fb95af        vieux/sshfs:newest   sshFS plugin for Docker   true

Sign off

Signal out of dockerhub.

geekflare@bestnich:/residence/geekflare$ docker logout

Eradicating login credentials for https://index.docker.io/v1/

Conclusion

I hope by now you will have a great understanding of the docker instructions. Attempt these instructions in your improvement or lab atmosphere to follow and study.

For those who’re serious about studying Docker and Kubernetes, take a look at this on-line course.

Rate this post
porno izle altyazılı porno porno