欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker操作

程序员文章站 2022-06-13 16:10:30
...

[root@node1 ~]# cd /opt/

[root@node1 opt]# ls

apache-flume-1.9.0-bin.tar.gz   apache-zookeeper-3.6.3-bin.tar.gz               hadoop-3.0.0                      mirrors.cgi?action=download                nginx-1.19.1.tar.gz

apache-hive-2.1.1-bin.tar.gz    flink-1.7.0                                     iceberg-flink-runtime-0.10.0.jar  mirrors.cgi?action=download.1              rh

apache-pulsar-2.7.2             flink-1.7.0-bin-hadoop28-scala_2.12.tgz         jdk1.8.0_131                      mysql-5.6.33-linux-glibc2.5-x86_64.tar.gz  scala-2.12.8.tgz

apache-pulsar-2.7.2-bin.tar.gz  flink-sql-connector-hive-2.3.6_2.11-1.11.0.jar  kafka_2.13-2.8.0.tgz              nacos                                      sqoop-1.4.7.tar.gz

[root@node1 opt]# systemctl status mysql

Unit mysql.service could not be found.

[root@node1 opt]# systemctl status docker

?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@node1 opt]# systemctl start docker

[root@node1 opt]# systemctl status docker

?docker.service - Docker Application Container Engine

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

   Active: active (running) since Thu 2021-06-03 14:53:07 CST; 3s ago

     Docs: http://docs.docker.com

 Main PID: 4396 (dockerd-current)

    Tasks: 17

   CGroup: /system.slice/docker.service

           忖4396 /usr/bin/dockerd-current --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current --default-runtime=docker-runc --exec-opt native.cgroupdriver=systemd --userland-proxy-pat...

           忖4402 /usr/bin/docker-containerd-current -l unix:///var/run/docker/libcontainerd/docker-containerd.sock --metrics-interval=0 --start-timeout 2m --state-dir /var/run/docker/libcontainerd/...

 

Jun 03 14:53:04 node1 dockerd-current[4396]: time="2021-06-03T14:53:04.446068657+08:00" level=info msg="libcontainerd: new containerd process, pid: 4402"

Jun 03 14:53:05 node1 dockerd-current[4396]: time="2021-06-03T14:53:05.734834925+08:00" level=info msg="Graph migration to content-addressability took 0.00 seconds"

Jun 03 14:53:05 node1 dockerd-current[4396]: time="2021-06-03T14:53:05.736392737+08:00" level=info msg="Loading containers: start."

Jun 03 14:53:05 node1 dockerd-current[4396]: time="2021-06-03T14:53:05.865123160+08:00" level=info msg="Firewalld running: true"

Jun 03 14:53:06 node1 dockerd-current[4396]: time="2021-06-03T14:53:06.873226021+08:00" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon opt...d IP address"

Jun 03 14:53:07 node1 dockerd-current[4396]: time="2021-06-03T14:53:07.070178713+08:00" level=info msg="Loading containers: done."

Jun 03 14:53:07 node1 dockerd-current[4396]: time="2021-06-03T14:53:07.212263384+08:00" level=info msg="Daemon has completed initialization"

Jun 03 14:53:07 node1 dockerd-current[4396]: time="2021-06-03T14:53:07.212305820+08:00" level=info msg="Docker daemon" commit="cccb291/1.13.1" graphdriver=overlay2 version=1.13.1

Jun 03 14:53:07 node1 systemd[1]: Started Docker Application Container Engine.

Jun 03 14:53:07 node1 dockerd-current[4396]: time="2021-06-03T14:53:07.224890099+08:00" level=info msg="API listen on /var/run/docker.sock"

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

[root@node1 opt]# docker images

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE

docker.io/kafkaesqueio/pulsar   2.6.2.1.0.1-beta2   b6054dcca615        6 days ago          1.95 GB

docker.io/wurstmeister/kafka    latest              4a83ed5f062f        12 days ago         438 MB

docker.io/redis                 latest              bc8d70f9ef6c        3 weeks ago         105 MB

docker.io/mysql                 latest              c0cdc95609f1        3 weeks ago         556 MB

docker.io/mysql                 <none>              a7a67c95e831        13 months ago       541 MB

docker.io/tomcat                latest              927899a31456        13 months ago       647 MB

docker.io/nginx                 latest              602e111c06b6        13 months ago       127 MB

docker.io/jaspeen/oracle-11g    latest              0c8711fe4f0f        5 years ago         281 MB

[root@node1 opt]# docker run --help

 

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

 

Run a command in a new container

 

Options:

      --add-host list                         Add a custom host-to-IP mapping (host:ip) (default [])

  -a, --attach list                           Attach to STDIN, STDOUT or STDERR (default [])

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

      --blkio-weight-device weighted-device   Block IO weight (relative device weight) (default [])

      --cap-add list                          Add Linux capabilities (default [])

      --cap-drop list                         Drop Linux capabilities (default [])

      --cgroup-parent string                  Optional parent cgroup for the container

      --cidfile string                        Write the container ID to the file

      --cpu-count int                         CPU count (Windows only)

      --cpu-percent int                       CPU percent (Windows only)

      --cpu-period int                        Limit CPU CFS (Completely Fair Scheduler) period

      --cpu-quota int                         Limit CPU CFS (Completely Fair Scheduler) quota

      --cpu-rt-period int                     Limit CPU real-time period in microseconds

      --cpu-rt-runtime int                    Limit CPU real-time runtime in microseconds

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

      --cpus decimal                          Number of CPUs (default 0.000)

      --cpuset-cpus string                    CPUs in which to allow execution (0-3, 0,1)

      --cpuset-mems string                    MEMs in which to allow execution (0-3, 0,1)

      --credentialspec string                 Credential spec for managed service account (Windows only)

  -d, --detach                                Run container in background and print container ID

      --detach-keys string                    Override the key sequence for detaching a container

      --device list                           Add a host device to the container (default [])

      --device-read-bps throttled-device      Limit read rate (bytes per second) from a device (default [])

      --device-read-iops throttled-device     Limit read rate (IO per second) from a device (default [])

      --device-write-bps throttled-device     Limit write rate (bytes per second) to a device (default [])

      --device-write-iops throttled-device    Limit write rate (IO per second) to a device (default [])

      --disable-content-trust                 Skip image verification (default true)

      --dns list                              Set custom DNS servers (default [])

      --dns-option list                       Set DNS options (default [])

      --dns-search list                       Set custom DNS search domains (default [])

      --entrypoint string                     Overwrite the default ENTRYPOINT of the image

  -e, --env list                              Set environment variables (default [])

      --env-file list                         Read in a file of environment variables (default [])

      --expose list                           Expose a port or a range of ports (default [])

      --group-add list                        Add additional groups to join (default [])

      --health-cmd string                     Command to run to check health

      --health-interval duration              Time between running the check (ns|us|ms|s|m|h) (default 0s)

      --health-retries int                    Consecutive failures needed to report unhealthy

      --health-timeout duration               Maximum time to allow one check to run (ns|us|ms|s|m|h) (default 0s)

      --help                                  Print usage

  -h, --hostname string                       Container host name

      --init                                  Run an init inside the container that forwards signals and reaps processes

      --init-path string                      Path to the docker-init binary

  -i, --interactive                           Keep STDIN open even if not attached

      --io-maxbandwidth string                Maximum IO bandwidth limit for the system drive (Windows only)

      --io-maxiops uint                       Maximum IOps limit for the system drive (Windows only)

      --ip string                             Container IPv4 address (e.g. 172.30.100.104)

      --ip6 string                            Container IPv6 address (e.g. 2001:db8::33)

      --ipc string                            IPC namespace to use

      --isolation string                      Container isolation technology

      --kernel-memory string                  Kernel memory limit

  -l, --label list                            Set meta data on a container (default [])

      --label-file list                       Read in a line delimited file of labels (default [])

      --link list                             Add link to another container (default [])

      --link-local-ip list                    Container IPv4/IPv6 link-local addresses (default [])

      --log-driver string                     Logging driver for the container

      --log-opt list                          Log driver options (default [])

      --mac-address string                    Container MAC address (e.g. 92:d0:c6:0a:29:33)

  -m, --memory string                         Memory limit

      --memory-reservation string             Memory soft limit

      --memory-swap string                    Swap limit equal to memory plus swap: '-1' to enable unlimited swap

      --memory-swappiness int                 Tune container memory swappiness (0 to 100) (default -1)

      --name string                           Assign a name to the container

      --network string                        Connect a container to a network (default "default")

      --network-alias list                    Add network-scoped alias for the container (default [])

      --no-healthcheck                        Disable any container-specified HEALTHCHECK

      --oom-kill-disable                      Disable OOM Killer

      --oom-score-adj int                     Tune host's OOM preferences (-1000 to 1000)

      --pid string                            PID namespace to use

      --pids-limit int                        Tune container pids limit (set -1 for unlimited)

      --privileged                            Give extended privileges to this container

  -p, --publish list                          Publish a container's port(s) to the host (default [])

  -P, --publish-all                           Publish all exposed ports to random ports

      --read-only                             Mount the container's root filesystem as read only

      --restart string                        Restart policy to apply when a container exits (default "no")

      --rm                                    Automatically remove the container when it exits

      --runtime string                        Runtime to use for this container

      --security-opt list                     Security Options (default [])

      --shm-size string                       Size of /dev/shm, default value is 64MB

      --sig-proxy                             Proxy received signals to the process (default true)

      --stop-signal string                    Signal to stop a container, SIGTERM by default (default "SIGTERM")

      --stop-timeout int                      Timeout (in seconds) to stop a container

      --storage-opt list                      Storage driver options for the container (default [])

      --sysctl map                            Sysctl options (default map[])

      --tmpfs list                            Mount a tmpfs directory (default [])

  -t, --tty                                   Allocate a pseudo-TTY

      --ulimit ulimit                         Ulimit options (default [])

  -u, --user string                           Username or UID (format: <name|uid>[:<group|gid>])

      --userns string                         User namespace to use

      --uts string                            UTS namespace to use

  -v, --volume list                           Bind mount a volume (default [])

      --volume-driver string                  Optional volume driver for the container

      --volumes-from list                     Mount volumes from the specified container(s) (default [])

  -w, --workdir string                        Working directory inside the container

[root@node1 opt]# docker run --name mysqldb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d  mysql

3abc248885e1760db8276a0f84982b6d82323196bfc1cd77e8e5d0547f468b75

[root@node1 opt]# docker images

REPOSITORY                      TAG                 IMAGE ID            CREATED             SIZE

docker.io/kafkaesqueio/pulsar   2.6.2.1.0.1-beta2   b6054dcca615        6 days ago          1.95 GB

docker.io/wurstmeister/kafka    latest              4a83ed5f062f        12 days ago         438 MB

docker.io/redis                 latest              bc8d70f9ef6c        3 weeks ago         105 MB

docker.io/mysql                 latest              c0cdc95609f1        3 weeks ago         556 MB

docker.io/mysql                 <none>              a7a67c95e831        13 months ago       541 MB

docker.io/tomcat                latest              927899a31456        13 months ago       647 MB

docker.io/nginx                 latest              602e111c06b6        13 months ago       127 MB

docker.io/jaspeen/oracle-11g    latest              0c8711fe4f0f        5 years ago         281 MB

[root@node1 opt]# docker ps  

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                               NAMES

3abc248885e1        mysql               "docker-entrypoint..."   48 seconds ago      Up 46 seconds       0.0.0.0:3306->3306/tcp, 33060/tcp   mysqldb

[root@node1 opt]# mysql -uroot -p123456

bash: mysql: command not found...

[root@node1 opt]# systemctl status firewalld

?firewalld.service - firewalld - dynamic firewall daemon

   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)

   Active: active (running) since Thu 2021-06-03 14:03:52 CST; 56min ago

     Docs: man:firewalld(1)

 Main PID: 1175 (firewalld)

    Tasks: 2

   Memory: 820.0K

   CGroup: /system.slice/firewalld.service

           忖1175 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

 

Jun 03 14:53:06 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE' failed: iptables: No chain/ta... by that name.

Jun 03 14:53:06 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C DOCKER -i docker0 -j RETURN' failed: iptables: Bad rule (does a matching rule exist in that chain?).

Jun 03 14:53:06 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -D FORWARD -i docker0 -o docker0 -j DROP' failed: iptables: Bad rule (does a matching rule exist in that chain?).

Jun 03 14:53:06 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -i docker0 -o docker0 -j ACCEPT' failed: iptables: Bad rule (does a matchin... that chain?).

Jun 03 14:53:06 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -i docker0 ! -o docker0 -j ACCEPT' failed: iptables: Bad rule (does a match... that chain?).

Jun 03 14:53:06 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT' failed: ip... that chain?).

Jun 03 14:53:07 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C FORWARD -o docker0 -j DOCKER' failed: iptables: No chain/target/match by that name.

Jun 03 14:58:11 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C DOCKER -p tcp -d 0/0 --dport 3306 -j DNAT --to-destination 172.17.0.2:3306 ! -i docker... by that name.

Jun 03 14:58:11 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t filter -C DOCKER ! -i docker0 -o docker0 -p tcp -d 172.17.0.2 --dport 3306 -j ACCEPT' failed:... that chain?).

Jun 03 14:58:11 node1 firewalld[1175]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -t nat -C POSTROUTING -p tcp -s 172.17.0.2 -d 172.17.0.2 --dport 3306 -j MASQUERADE' failed: ipt... by that name.

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

[root@node1 opt]# systemctl stop firewalld

[root@node1 opt]#  docker exec -it 3abc248885e1 /bin/bash

root@3abc248885e1:/# mysql -uroot -p

Enter password: 

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

Your MySQL connection id is 13

Server version: 8.0.25 MySQL Community Server - GPL

 

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

 

Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

--  mysql 出现Client does not support authentication protocol requested by server解决方案

mysql> select host,user,plugin,authentication_string from mysql.user;

+-----------+------------------+-----------------------+------------------------------------------------------------------------+

| host      | user             | plugin                | authentication_string                                                  |

+-----------+------------------+-----------------------+------------------------------------------------------------------------+

z %     [RAa3Vdcn9HWRn6BKYd0fjqYGrDjbdqZlUyVHGktJEl018 | $A$005$7b^-3#b

| localhost | mysql.infoschema | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |

| localhost | mysql.session    | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |

| localhost | mysql.sys        | caching_sha2_password | $A$005$THISISACOMBINATIONOFINVALIDSALTANDPASSWORDTHATMUSTNEVERBRBEUSED |

| localhost | root             | caching_sha2_password | $A$005$%'oYB9S1gP)Sd

                                                                             9lj6GtGbI2Nlv8a59VW23Q2jDl5HQgBZuielhg/kY9dx5 |

+-----------+------------------+-----------------------+------------------------------------------------------------------------+

5 rows in set (0.13 sec)

 

mysql> ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';

Query OK, 0 rows affected (0.11 sec)

 

mysql>