Skip to main content


Run systemd in container

FROM centos:7
MAINTAINER "Gimo" <[email protected]>
ENV container docker
RUN yum -y update; yum clean all
RUN yum -y install systemd; yum clean all; \
(cd /lib/systemd/system/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/*; \
rm -f /lib/systemd/system/*udev*; \
rm -f /lib/systemd/system/*initctl*; \
rm -f /lib/systemd/system/*;\
rm -f /lib/systemd/system/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]
docker build -t systemd_centos .
docker run --privileged -d -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd_centos

Ref: Running systemd within a docker container

Save and load docker images

docker save ubuntu -o ubuntu.tar
docker load -i ubuntu.tar

Update image using docker-compose

docker-compose pull && docker-compose up -d

Ref: build process - how to get docker-compose to use the latest image from repository - Stack Overflow

Remove unused images

docker image prune -a

Ref: How to remove old and unused Docker images - Stack Overflow

Access host port from container

On Linux, add --add-host=host.docker.internal:host-gateway to your Docker command to enable this feature. (See below for Docker Compose configuration.)

Use your internal IP address or connect to the special DNS name host.docker.internal which will resolve to the internal IP address used by the host.

To enable this in Docker Compose on Linux, add the following lines to the container definition:

- "host.docker.internal:host-gateway"

Ref: How to access host port from docker container - Stack Overflow

Pull docker image via proxy

sudo systemctl edit docker

sudo systemctl restart docker

Ref: Cannot download Docker images behind a proxy - Stack Overflow