如何进入服务容器内部
**
##################################################################
使用exec命令进入
[root@foundation15 ~]# docker run -d --name vm1 nginx
41a0572cdd0e3b70e09ac9f74dcfc341c21ceef2c07dee714f0a24d94b1aa77f
[root@foundation15 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
41a0572cdd0e nginx "nginx -g 'daemon ..." 4 seconds ago Up 3 seconds 80/tcp vm1
[root@foundation15 ~]# docker container exec -it vm1 bash
root@41a0572cdd0e:/#
##################################################################
##########################################################################
创建容器时直接打开交互界面shell
[root@foundation15 ~]# docker run -it --name vm2 nginx bash
root@d5f787395834:/# ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
##########################################################
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
**
使用supervisord同时打开多个服务
**
封装一个新的镜像
####################################################################
编写新的Dockerfile
FROM rhel7
EXPOSE 22 80
COPY yum.repo /etc/yum.repos.d/yum.repo
RUN rpmdb --rebuilddb&& yum install -y openssh-server supervisor openssh-clients httpd&& yum clean all root:westos | chpasswd
RUN echo root:westos | chpasswd
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -q -N ""
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -q -N ""
COPY supervisord.conf /etc/supervisord.conf
CMD ["/usr/bin/supervisord"]
ssh部分生产环境可以写在一起 但实验化环境为了清除了理解过程分开写
supervisord配置文件
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:httpd]
command=/usr/sbin/httpd
####################################################
######################################################
build创建新镜像即可
[root@foundation15 docker]# docker build -t rhel7:v3 .
Sending build context to Docker daemon 7.168 kB
Step 1/9 : FROM rhel7
---> 0a3eb3fde7fd
Step 2/9 : EXPOSE 22 80
---> Using cache
---> 1ec0317a22b7
Step 3/9 : COPY yum.repo /etc/yum.repos.d/yum.repo
---> Using cache
---> de3c79e1b8df
Step 4/9 : RUN rpmdb --rebuilddb&& yum install -y openssh-server supervisor openssh-clients httpd&& yum clean all root:westos | chpasswd
---> Using cache
---> 4b108c1cd6ab
Step 5/9 : RUN echo root:westos | chpasswd
---> Running in d549e2f4dc2d
---> 916e64011fea
Removing intermediate container d549e2f4dc2d
Step 6/9 : RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -q -N ""
---> Running in 23d52c8a575c
---> cba68be457bc
Removing intermediate container 23d52c8a575c
Step 7/9 : RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -q -N ""
---> Running in 200c813e6e7e
---> 6317ae0edd48
Removing intermediate container 200c813e6e7e
Step 8/9 : COPY supervisord.conf /etc/supervisord.conf
---> 2dd5c9ef0be1
Removing intermediate container 2666c11d86dd
Step 9/9 : CMD /usr/bin/supervisord
---> Running in 2a15083c3b60
---> 15846d8145b3
Removing intermediate container 2a15083c3b60
Successfully built 15846d8145b3
[root@foundation15 docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
rhel7 v3 15846d8145b3 13 seconds ago 202 MB
##################################################################
##################################################################
使用新镜像创建容器
[root@foundation15 docker]# docker run -d --name vm1 -v /tmp/docker/web/:/var/www/html rhel7:v3
5d6054ef42d8c01dfb9191b90ade1302fa85db3b12e6b775225623ed36bda53b
[root@foundation15 docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d6054ef42d8 rhel7:v3 "/usr/bin/supervisord" 2 seconds ago Up 2 seconds 22/tcp, 80/tcp vm1
##################################################################
##################################################################
测试
[root@foundation15 docker]# ssh 172.17.0.2
The authenticity of host '172.17.0.2 (172.17.0.2)' can't be established.
RSA key fingerprint is 38:a9:59:49:4b:2f:bc:32:25:81:72:ce:aa:67:b4:74.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.0.2' (RSA) to the list of known hosts.
root@172.17.0.2's password:
-bash-4.2# ip addr
-bash: ip: command not found
-bash-4.2# ^C
-bash-4.2# ^C
-bash-4.2# ^C
-bash-4.2# logout
Connection to 172.17.0.2 closed.
[root@foundation15 docker]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d6054ef42d8 rhel7:v3 "/usr/bin/supervisord" 50 seconds ago Up 50 seconds 22/tcp, 80/tcp vm1
[root@foundation15 docker]# curl 172.17.0.2
www.westos.org
##################################################################
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
**有需要的联系我哦微信yxxy1717 qq 2173384986
doker中关于内存的使用
**
目前 Docker 支持内存资源限制选项
-m, --memory=""
Memory limit (format: <number>[<unit>]). Number is a positive integer. Unit can be one of b, k, m, or g. Minimum is 4M.
--memory-swap=""
Total memory limit (memory + swap, format: <number>[<unit>]). Number is a positive integer. Unit can be one of b, k, m, or g.
--memory-swappiness=""
Tune a container’s memory swappiness behavior. Accepts an integer between 0 and 100.
--shm-size=""
Size of /dev/shm. The format is <number><unit>. number must be greater than 0. Unit is optional and can be b (bytes), k (kilobytes), m (megabytes), or g(gigabytes). If you omit the unit, the system uses bytes. If you omit the size entirely, the system uses 64m.
根据实际需求设置,这里不作过多的介绍
--memory-reservation=""
Memory soft limit (format: <number>[<unit>]). Number is a positive integer. Unit can be one of b, k, m, or g.
--kernel-memory=""