本文主要是介绍redhat7 安装 docker,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
安装命令
[root@localhost ~]# cat > /etc/yum.repos.d/docker.repo << EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
[root@localhost ~]# docker pull java
Using default tag: latest
Warning: failed to get default registry endpoint from daemon (Cannot connect to themon at unix:///var/run/docker.sock. Is the docker daemon running?). Using system tps://index.docker.io/v1/
Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker ing?
[root@localhost ~]# systemctl start docker.service
常用命令
docker pull
[root@localhost ~]# 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
docker ps
docker ps -a
docker run
1.临时运行,退出控制台就停止
[root@localhost ~]# docker run -it java
root@7e189f686e82:/# psPID TTY TIME CMD1 ? 00:00:00 bash5 ? 00:00:00 ps
root@7e189f686e82:/# docker-java-home ps ^C
root@7e189f686e82:/# exit
exit
[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2.临时查看
[root@localhost ~]# 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@localhost ~]# docker run -it java env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=9700976b4087
TERM=xterm
LANG=C.UTF-8
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
JAVA_VERSION=8u111
JAVA_DEBIAN_VERSION=8u111-b14-2~bpo8+1
CA_CERTIFICATES_JAVA_VERSION=20140324
HOME=/root
docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG…] 决定容器的运行方式,前台执行还是后台执行
docker run后面追加-d=true或者-d,那么容器将会运行在后台模式。 docker exec来进入到到该容器中,或者attach重新连接容器的会话
进行交互式操作(例如Shell脚本),那我们必须使用-i -t参数同容器进行数据交互
docker run时没有指定–name,那么deamon会自动生成一个随机字符串UUID
Docker时有自动化的需求,你可以将containerID输出到指定的文件中(PIDfile): –cidfile=””
–cidfile=””
Docker的容器是没有特权的,例如不能在容器中再启动一个容器。这是因为默认情况下容器是不能访问任何其它设 备的。但是通过”privileged”,容器就拥有了访问任何其它设备的权限。
命令方式传入 参数
[root@localhost ~]# docker create --name mysql1 -e MYSQL_ROOT_PASSWORD=123456 -p 3 306:3306 mysql
a4d03135f4b3ac0ee76ad4abeb5ed82601b8e5e348325e3ce6bbb73302206340[root@localhost ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
a4d03135f4b3 mysql "docker-entrypoint..." 33 seconds ago Created
b74701291341 mysql "docker-entrypoint..." 4 minutes ago Exited (0) 4 minut
adb0e13259c5 java "java -version" 17 minutes ago Exited (0) 17 minu
[root@localhost ~]# docker start mysql1
最后参数显示在环境变量中:
[root@localhost ~]# docker exec mysql1 env
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=a4d03135f4b3
MYSQL_ROOT_PASSWORD=123456
GOSU_VERSION=1.7
MYSQL_MAJOR=8.0
MYSQL_VERSION=8.0.11-1debian9
HOME=/root
1.停用全部运行中的容器:
docker stop (dockerps−q)2.删除全部容器:dockerrm ( d o c k e r p s − q ) 2. 删 除 全 部 容 器 : d o c k e r r m (docker ps -aq)
3.一条命令实现停用并删除容器:
这篇关于redhat7 安装 docker的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!