(二)docker的部署安装,配置,基础命令

一、docker 的安装部署

这里不过多介绍,下面这两个linux发型版 安装可以参考

ubuntu的 docker-ce安装

centos7的 docker-ce安装

二.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}:
--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:
https_proxy=xxxxxx:

三.Docker基础命令

docker search   搜索的相关镜像按热度排名 列表展示

[root@docker ~]# docker search java
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
node Node.js is a JavaScript-based platform for s… [OK]
tomcat Apache Tomcat is an open source implementati… [OK]
java Java is a concurrent, class-based, and objec… [OK]
openjdk OpenJDK is an open-source implementation of … [OK]
ghost Ghost is a free and open source blogging pla… [OK]
anapsix/alpine-java Oracle Java (and ) with GLIBC 2.23 over A… [OK]
jetty Jetty provides a Web server and javax.servle… [OK]
couchdb CouchDB is a database that uses JSON for doc… [OK]
tomee Apache TomEE is an all-Apache Java EE certif… [OK]
ibmjava Official IBM® SDK, Java™ Technology Edition … [OK]
groovy Apache Groovy is a multi-faceted language fo… [OK]
lwieske/java- Oracle Java Container - Full + Slim - Base… [OK]
cloudbees/jnlp-slave-with-java-build-tools Extends cloudbees/java-build-tools docker im… [OK]
zabbix/zabbix-java-gateway Zabbix Java Gateway [OK]
davidcaste/alpine-java-unlimited-jce Oracle Java (and ) with GLIBC 2.21 over A… [OK]
frekele/java docker run --rm --name java frekele/java [OK]
blacklabelops/java Java Base Images. [OK]
fabric8/s2i-java S2I Builder Image for plain Java applications
rightctrl/java Oracle Java [OK]
jorgemoralespou/s2i-java OpenShift's Java S2I Builder image. Suitable… 2 [OK]
appuio/s2i-maven-java S2I Builder with Maven and Java [OK]
cfje/java-buildpack Java Buildpack CI Image
cfje/java-test-applications Java Test Applications CI Image
thingswise/java-docker Java + dcd [OK]
appuio/s2i-gradle-java S2I Builder with Gradle and Java [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 weeks ago .85kB
hello-world latest e38bc07ac18e weeks ago .85kB
java latest d23bdf5b1b1b 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-~bpo8+-b14)
OpenJDK -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
pts/ :: ps
决定容器的运行方式,前台执行还是后台执行
进行交互式操作(例如Shell脚本),那我们必须使用-i -t参数同容器进行数据交互
docker run时没有指定--name,那么deamon会自动生成一个随机字符串UUID
Docker时有自动化的需求,你可以将containerID输出到指定的文件中(PIDfile): --cidfile="" --cidfile=""
Docker的容器是没有特权的,例如不能在容器中再启动一个容器。这是因为默认情况下容器是不能访问任何其它设 备的。但是通过"privileged",容器就拥有了访问任何其它设备的权限。

容器生命周期相关指令
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" seconds ago Created myjava
3eafb4d18f10 java "ip addr" About a minute ago Exited () About a minute ago elegant_ardinghelli
a01bb5aa8180 java "ipaddr" About a minute ago Created wizardly_leavitt
b6c29c6751cf java "ps" minutes ago Exited () minutes ago competent_varahamihira
70f07df484aa java "uname" minutes ago Exited () minutes ago sharp_keller
1e569804e429 java "java -version" minutes ago Exited () minutes ago kind_bell
934143e28fa2 hello-world "/hello" hours ago Exited () hours ago competent_khorana
48563e0fd4ca hello-world "/hello" hours ago Exited () hours ago wonderful_albattani
[root@docker ~]# docker start myjava
myjava
[root@docker ~]# docker create --name mysqlsrv1 -e MYSQL_ROOT_PASSWORD= -p : 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…" minutes ago Up minutes 0.0.0.0:->/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" hours ago Exited () hours ago competent_khorana
48563e0fd4ca hello-world "/hello" hours ago Exited () 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 ~]# 
上一篇:struts2标签


下一篇:android支付宝app支付(原生态)-包括android前端与java后台