一、docker 的安装部署
这里不过多介绍,下面这两个linux发型版 安装可以参考
二.docker配置文件
重要参数解释:
OPTIONS 用来控制Docker Daemon进程参数 -H 表示Docker Daemon绑定的地址, -H=unix:///var/run/docker.sock -H=tcp://0.0.0.0:2375 --registry-mirror表示Docker Registry的镜像地址--registry-mirror=http://4bc5abeb.m.daocloud.io --insecure-registry表示(本地)私有Docker Registry的地址, --insecure-registry ${pivateRegistyHost}:5000 --selinux-enabled是否开启SELinux,默认开启 --selinux-enabled=true --bip 表示网桥docker0使用指定CIDR网络地址,--bip=172.17.42.1 -b 表示采用已经创建好的网桥, -b=xxx 重要参数解释: OPTIONS=-H=unix:///var/run/docker.sock -H=tcp://0.0.0.0:2375 --registrymirror=http://4bc5abeb.m.daocloud.io --selinux-enabled=true 下面是代理的设置 http_proxy=xxxxx:8080 https_proxy=xxxxxx:8080
三.Docker基础命令
docker search 搜索的相关镜像按热度排名 列表展示
[root@docker ~]# docker search java NAME DESCRIPTION STARS OFFICIAL AUTOMATED node Node.js is a JavaScript-based platform for s… 5594 [OK] tomcat Apache Tomcat is an open source implementati… 1847 [OK] java Java is a concurrent, class-based, and objec… 1721 [OK] openjdk OpenJDK is an open-source implementation of … 967 [OK] ghost Ghost is a free and open source blogging pla… 760 [OK] anapsix/alpine-java Oracle Java 8 (and 7) with GLIBC 2.23 over A… 311 [OK] jetty Jetty provides a Web server and javax.servle… 245 [OK] couchdb CouchDB is a database that uses JSON for doc… 205 [OK] tomee Apache TomEE is an all-Apache Java EE certif… 51 [OK] ibmjava Official IBM® SDK, Java™ Technology Edition … 47 [OK] groovy Apache Groovy is a multi-faceted language fo… 41 [OK] lwieske/java-8 Oracle Java 8 Container - Full + Slim - Base… 38 [OK] cloudbees/jnlp-slave-with-java-build-tools Extends cloudbees/java-build-tools docker im… 18 [OK] zabbix/zabbix-java-gateway Zabbix Java Gateway 12 [OK] davidcaste/alpine-java-unlimited-jce Oracle Java 8 (and 7) with GLIBC 2.21 over A… 9 [OK] frekele/java docker run --rm --name java frekele/java 9 [OK] blacklabelops/java Java Base Images. 8 [OK] fabric8/s2i-java S2I Builder Image for plain Java applications 5 rightctrl/java Oracle Java 2 [OK] jorgemoralespou/s2i-java OpenShift's Java S2I Builder image. Suitable… 2 [OK] appuio/s2i-maven-java S2I Builder with Maven and Java 1 [OK] cfje/java-buildpack Java Buildpack CI Image 0 cfje/java-test-applications Java Test Applications CI Image 0 thingswise/java-docker Java + dcd 0 [OK] appuio/s2i-gradle-java S2I Builder with Gradle and Java 0 [OK]
docker pull 从镜像站拉取镜像 tag:latest 标签为 最新
[root@docker ~]# docker pull java Using default tag: latest latest: Pulling from library/java 5040bd298390: Pull complete fce5728aad85: Pull complete 76610ec20bf5: Pull complete 60170fec2151: Pull complete e98f73de8f0d: Pull complete 11f7af24ed9c: Pull complete 49e2d6393f32: Pull complete bb9cdec9c7f3: Pull complete Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d Status: Downloaded newer image for java:latest
docker images
[root@docker ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest e38bc07ac18e 6 weeks ago 1.85kB hello-world latest e38bc07ac18e 6 weeks ago 1.85kB java latest d23bdf5b1b1b 16 months ago 643MB
docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
docker run后面追加-d=true或者-d,那么容器将会运行在后台模式。 docker exec来进入到到该容器中,或者attach重新连接容器的会话
[root@docker ~]# docker run -it java java -version openjdk 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@docker ~]# docker run -it java uname Linux [root@docker ~]# docker run -it java ps PID TTY TIME CMD 1 pts/0 00:00:00 ps
容器生命周期相关指令
docker create/start/stop/pause/unpause
[root@docker ~]# docker create -it --name="myjava" java java version 872e0e5104d1a137e96621c50a6a9e948073e6ba3ce4ee9bcdbf35e1e0326d20 [root@docker ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 872e0e5104d1 java "java version" 11 seconds ago Created myjava 3eafb4d18f10 java "ip addr" About a minute ago Exited (0) About a minute ago elegant_ardinghelli a01bb5aa8180 java "ipaddr" About a minute ago Created wizardly_leavitt b6c29c6751cf java "ps" 4 minutes ago Exited (0) 4 minutes ago competent_varahamihira 70f07df484aa java "uname" 4 minutes ago Exited (0) 4 minutes ago sharp_keller 1e569804e429 java "java -version" 4 minutes ago Exited (0) 4 minutes ago kind_bell 934143e28fa2 hello-world "/hello" 2 hours ago Exited (0) 2 hours ago competent_khorana 48563e0fd4ca hello-world "/hello" 3 hours ago Exited (0) 3 hours ago wonderful_albattani
[root@docker ~]# docker start myjava
myjava
[root@docker ~]# docker create --name mysqlsrv1 -e MYSQL_ROOT_PASSWORD=123 -p 3306:3306 mysql 251bdc0842d93a6c957a283aecb65740813653300000e4d6aca8aeac9ca28333
[root@docker ~]# docker start mysqlsrv1
mysqlsrv1
[root@docker ~]# docker ps |grep mysql
251bdc0842d9 mysql "docker-entrypoint.s…" About a minute ago Up 29 seconds 0.0.0.0:3306->3306/tcp mysqlsrv1
[root@docker ~]# netstat -lntup|grep 3306
tcp6 0 0 :::3306 :::* LISTEN 41446/docker-proxy
[root@docker ~]# docker exec -it mysqlsrv1 /bin/bash
root@251bdc0842d9:/# mysql -uroot -p123456 -h10.0.0.7
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.11 MySQL Community Server - GPL
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
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>
docker stop 命令
[root@docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 251bdc0842d9 mysql "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:3306->3306/tcp mysqlsrv1 [root@docker ~]# docker stop 251bdc0842d9 251bdc0842d9 [root@docker ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
docker rm命令
[root@docker ~]# docker ps -a|grep hello 934143e28fa2 hello-world "/hello" 2 hours ago Exited (0) 2 hours ago competent_khorana 48563e0fd4ca hello-world "/hello" 3 hours ago Exited (0) 3 hours ago wonderful_albattani [root@docker ~]# docker rm 934143e28fa2 934143e28fa2 [root@docker ~]# docker rm 48563e0fd4ca 48563e0fd4ca [root@docker ~]# docker ps -a|grep hello
[root@docker ~]#