Docker advocates the PAAs, where each container should be a product, and streamlining is the core.
So many of the underlying images start up, and a service process does not.
Based on each container should be a product of the purpose, as long as a port to provide services, so Docker by default does not provide fixed IP solution.
That is, all containers have no IP, and the host opens the port and maps to a container.
So far, I've used the original routine to use Docker (fixed IP, where each container listens at least 22 ports and the ports it serves).
Here is the process of making the image:
# makes a container that provides an sshd service, and the image is robust enough to meet a variety of application scenarios. [[email protected] ~]# mkdir -p build_dockerfile/sshd[[email protected] ~]# cd /root/build_dockerfile/sshd# run.sh plays a role similar to the /etc/rc.local in the original system, will want to # Start-up service pre-writes to the file, and then makes the mirror, because # needs to take the file as Post-Install to run, and run each time the mirror is started. [[email protected] sshd]# vim run.sh#!/bin/bash/usr/sbin/sshd -d# Write a Dockerfile [[email protected] sshd]# vim dockerfilefrom docker.io/centos:7maintainer zhengtong [email protected]run mkdir /var/run/sshd -prun echo ' root:123456 ' | chpasswdRUN echo "vm.hugetlb_shm_group = 501" >> /etc/ sysctl.confrun yum install wget screen unzip zip bridge-utils bc net-tools vim sysstat mlocate gcc gcc-c++ glibc-devel libstdc++ libstdc++-devel make dos2unix tar Openssl-devel ncurses-devel epel-release lrzsz nc bzip2-devel ntpdate compat-libstdc++* libxp* xscreensaver gnome-libs glibc glibc-common pdksh control-center compat-db binutils openssh* libaio.so.1* libgcc_s.so.1* glibc*i686 glibc* -yRUN ssh-keygen -t rsa1 -f /etc/ssh/ssh_host_rsa_keyrun ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_keyadd run.sh /run.shrun chmod 777 /run.shexpose 22cmd ["/run.sh"]# build a new mirror: with an image [[email protected] sshd]# automatically start the SSH service after opening You can view the current situation in the image library when you are finished making docker build -t centos:sshd .# . [[Email protected] 01_yumed]# docker imagesrepository tag IMAGE ID CREATED VIRTUAL SIZEcentos sshd e775e34475b8 2 minutes ago 853.4mbdocker.io/centos 7 8b44529354f3 4 minutes ago 202.6 mb
Note: You can write commands that are started by multiple services into the run.sh file, and then make the image, so that this image is more than just an sshd service.
Making a Docker image