Howto
Build
git clone https://github.com/neomutt/test-docker docker build test-docker # ... # Lots of logging # ... # Successfully built IMAGE_ID
To create a named image, use:
docker build -t dovecot-img test-docker
Run
If you have permission to open ports below 1024 (if you're root), you can run (constraining those ports only for tcp connections):
docker run -p 110:110/tcp -p 143:143/tcp -p 993:993/tcp -p 994:994/tcp IMAGE_ID
otherwise, run this to map the ports to higher-number ports:
docker run -P IMAGE_ID
You probably don't want to open ports in your system if you don't need to. Thus, you can tie it too your loopback connection only as follows. By the way, it seems easier to name the container since you know how to reach it. Also, you can remove the container as soon as it finish the execution.
docker run -it --rm --name=dovecot-container \
-p 127.0.0.1:110:110/tcp \
-p 127.0.0.1:143:143/tcp \
-p 127.0.0.1:993:993/tcp \
-p 127.0.0.1:994:994/tcp \
dovecot-imgAccess
To get a shell in the Docker, find the ContainerID:
docker container ls # CONTAINER ID IMAGE ... # ae0090e01571 2a24eb92c691 ...
then run:
docker exec -it CONTAINER_ID /bin/shTesting
Telnet is the easier way to get a quick check using the dovecot server you just created
telnet localhost 143 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. * OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
Three users are available in the container:
| User | Password |
|---|---|
fulano |
secret |
cicrano |
unknown |
beltrano |
puzzle |
Again, it is possible to make a quick check while with the telnet open:
a login fulano secret
And list all folders
a1 list "" *
See a full list of raw IMAP commands here.
Cleaning up
The generated images are kept in a hidden place by docker. You can list them doing the following:
docker images
Removing an image is as easy as
docker rmi <name or hash of the image>
However, no container that was created based on that image should exist. To list all the containers in your machine:
docker ps --all
And, to remove a container:
docker rm <name or hash of the container>
Extra tools
The script run-container.sh will create a folder named as homefs and than create a container where that folder is used as \home. Once the container server is stopped, the container itself will be auto-removed (--rm), however all the changes in the homefs will be kept.
Notes: To make homefs read/writable to the Docker you may also have to:
-
Add 'write' file permissions to everything.
chmod -R og+rwX homefsAll the files/dirs will appear in the Docker as owned by your user id. -
Set the SELinux permissions on the dirs/files
chcon -Rt svirt_sandbox_file_t homefs(For security, Docker isn't allowed to read from a user's home dir).