(二)docker的部署安裝,配置,基礎命令

1、docker 的安裝部署

這裏不過多介紹,下面這兩個linux髮型版 安裝能夠參考html

ubuntu的 docker-ce安裝java

centos7的 docker-ce安裝node

二.docker配置文件

重要參數解釋:mysql

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   搜索的相關鏡像按熱度排名 列表展現linux

[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 標籤爲 最新sql

[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 imagesdocker

[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...]ubuntu

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

 

決定容器的運行方式,前臺執行仍是後臺執行
進行交互式操做(例如Shell腳本),那咱們必須使用-i -t參數同容器進行數據交互
docker run時沒有指定--name,那麼deamon會自動生成一個隨機字符串UUID
Docker時有自動化的需求,你能夠將containerID輸出到指定的文件中(PIDfile): --cidfile="" --cidfile=""
Docker的容器是沒有特權的,例如不能在容器中再啓動一個容器。這是由於默認狀況下容器是不能訪問任何其它設 備的。可是經過"privileged",容器就擁有了訪問任何其它設備的權限。

容器生命週期相關指令
docker create/start/stop/pause/unpausecentos

[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
mysqlsrv1tomcat

[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 ~]# 
相關文章
相關標籤/搜索