1、添加创建镜像的配置文件
vim Dockerfile
输入以下内容:
FROM centos:centos6
MAINTAINER xxx"xxx@honghe-tech.com"
RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN yum install -y openssh-server sudo mysql-server mysql supervisor nginx
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN useradd admin
RUN echo "admin:admin" | chpasswd
RUN echo "admin
ALL=(ALL)
ALL" >> /etc/sudoers
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN mkdir /var/run/sshd
RUN /etc/init.d/mysqld start &&\
mysql -e "grant all privileges on *.* to 'root'@'%' identified by 'letmein';"&&\
mysql -e "grant all privileges on *.* to 'root'@'localhost' identified by 'letmein';"&&\
mysql -u root -pletmein -e "show databases;"
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisord.conf
EXPOSE 22 80 3306
CMD ["/usr/bin/supervisord"]
2、添加容器启动的配置文件
vim supervisord.conf
输入以下内容:
#command 标示容器启动时,需要执行的命令
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:mysqld]
command=/usr/bin/mysqld_safe
[program:nginx]
command=/usr/sbin/nginx
3、创建镜像
docker build -t my_centos .
4、docker run -d --name=my_centos -p 50001:22 -p 50002:3306 -p 8080:80 my_centos
5、通过ssh 登录容器
ssh admin@localhost -p 50001
密码为:admin
6、通过浏览器访问nginx
localhost:8080
7、远程连接容器中的mysql
mysql -h 0.0.0.0 -u root -P 50002 -p
密码为:letmein
# 0.0.0.0 为容器ip地址
通过命令查看容器映射的ip地址
root@xxx-All-Series:~/docker/centos# docker ps -a
CONTAINER ID
IMAGE
COMMAND
CREATED
STATUS
PORTS
NAMES
62d473045406
centos_nginx_test2:latest
/usr/bin/supervisord
55 minutes ago
Up 55 minutes
0.0.0.0:49153->22/tcp,
0.0.0.0
:49154->3306/tcp, 0.0.0.0:49155->80/tcp
nginx2
FROM centos:centos6
MAINTAINER xxx"xxx@honghe-tech.com"
RUN rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
RUN yum install -y openssh-server sudo mysql-server mysql supervisor nginx
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
RUN useradd admin
RUN echo "admin:admin" | chpasswd
RUN echo "admin
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN mkdir /var/run/sshd
RUN /etc/init.d/mysqld start &&\
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisord.conf
EXPOSE 22 80 3306
CMD ["/usr/bin/supervisord"]
2、添加容器启动的配置文件
#command 标示容器启动时,需要执行的命令
[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:mysqld]
command=/usr/bin/mysqld_safe
[program:nginx]
command=/usr/sbin/nginx
3、创建镜像
4、docker run -d --name=my_centos -p 50001:22 -p 50002:3306 -p 8080:80 my_centos
5、通过ssh 登录容器
6、通过浏览器访问nginx
7、远程连接容器中的mysql
CONTAINER ID
62d473045406