New to Docker - how to essentially make a cloneabl

2019-09-15 10:36发布

问题:

My goal is to use Docker to create a mail setup running postfix + dovecot, fully configured and ready to go (on Ubuntu 14.04), so I could easily deploy on several servers. As far as I understand Docker, the process to do this is:

  1. Spin up a new container (docker run -it ubuntu bash).
  2. Install and configure postfix and dovecot.
  3. If I need to shut down and take a break, I can exit the shell and return to the container via docker start <id> followed by docker attach <id>.

(here's where things get fuzzy for me)

At this point, is it better to export the image to a file, import on another server, and run it? How do I make sure the container will automatically start postfix, dovecot, and other services upon running it? I also don't quite understand the difference between using a Dockerfile to automate installations vs just installing it manually and exporting the image.

回答1:

  1. Configure multiple docker images using Dockerfiles

    Each docker container should run only one service. So one container for postfix, one for another service etc. You can have your running containers communicate with each other

  2. Build those images

  3. Push those images to a registry so that you can easily pull them on different servers and have the same setup.

  4. Pull those images on your different servers. You can pass ENV variables when you start a container to configure it.

You should not install something directly inside a running container. This defeat the pupose of having a reproducible setup with Docker.



回答2:

Your step #2 should be a RUN entry inside a Dockerfile, that is then used to run docker build to create an image.
This image could then be used to start and stop running containers as needed. See the Dockerfile RUN entry documentation. This is usually used with apt-get install to install needed components.

The ENTRYPOINT in the Dockerfile should be set to start your services. In general it is recommended to have just one process in each image.



标签: docker