Nethence NEWDOC OLDDOC Lab Webmail Your IP BBDock  

Operating Docker Containers

Now that the container is configured, you can continue using it in a run mode for operations.


Get into a container to quickly maintain it,

docker exec -ti <containername> bash

or try to get a grip an its shell or process already,

docker attach <containername>

note. to get out of the container (does this work only from a shell?) and keep the container (namely its init 1 process) up,

Ctrl-P Ctrl-Q


As most of the containers are Ubuntu powered,

apt -y update
apt full-upgrade
apt autoremove
dpkg -l | grep ^rc
#apt purge ...

Monitor & Audit

list the recorded containers,

docker ps -a

list the last created container details,

docker ps -l

show its output,

docker logs <containername>

ask what port corresponds on localhost to container’s port 8080,

docker port <containername> 8080

look for container’s processes,

docker top <containername>

Start / Stop

To stop it,

docker stop <containername>

to start it back,

docker start <containername>

If you used the guides on this website, remember, our images are originally powered by a debug/fake init, so you still need to exec or start the daemon manually,

docker exec -dti <containername> (start the daemon)


docker exec -dti <containername> bash
(start the daemon)

Backup & Change/Relaunch

If you want to make a backup of the container, well, first make sure that’s really what you want to do, as there are special tools to backup databases. And if you’re talking of the applications folders, why not use GIT or any versioning systems for deployments? Anyway if that’s what you want to do, look at the next point, it’s just like building an image based on the current status of the container.

If you even needs to change a runtime setting of the container (e.g. port & link), then you need to use the latest image you made or eventually rebuild one just in case,

apt -y update
apt -y full-upgrade
    apt -y autoremove
(eventually clean up things, like log folders)

docker commit -p <containername> <containername>.`date +%s`.status.before.destroy

you can then re-launch using the docker run shown at the top of the document, with the image being <containername>.datetag.ready or <containername>.datetag.status.before.destroy instead of custom/ubuntu.

Ship docker images

To retrieve official images, just,

docker pull <imgname>

To ship custom images, save it, send it and load it:

  1. to save e.g. custom/ubuntu,

    mkdir -p ~/images.archives/ cd ~/images.archives/

    app= docker save -o $app.image.tar custom/ubuntu

  2. then ship it to another docker host e.g.,

    scp -r ~/images.archives remoteuser@otherdockerhost:~/


rsync -avz --delete images.archives/ remoteuser@otherdockerhost:~/images.archives/
  1. finally load it on the other host e.g.,

    app= docker load < $app.image.tar

Ship docker containers

Export a container,

docker export <containername> > containername.container.tar

Emport a container,

cat <containername>.container.tar | docker import - <containername>

Tips & Tricks

to remove ALL containers (even those which are up),

docker rm `docker ps --no-trunc -aq`

to remove all exited containers,

docker rm `docker ps -q -f status=exited`