Commit 56a327db authored by ijaz ahmad's avatar ijaz ahmad Committed by GitHub
Browse files

Create start-containers-onboot-with-systemd

parent cbb8b878
#using systemd to run a service in a container and start it on boot.
#write the systemd service file
core@74fcea2a3d5a ~ $ cat postgres.service
Description=PostgreSQL container
ExecStartPre=-/usr/bin/docker stop postgres
ExecStartPre=-/usr/bin/docker rm postgres
ExecStart=/usr/bin/docker run --name postgres \
--volume /opt/db/postgres:/var/lib/pgsql/data \
ExecStop=/usr/bin/docker stop postgres
#copy it to systemd config dir
sudo cp postgres.service /etc/systemd/system
#enable on boot
sudo systemctl enable /etc/systemd/system/postgres.service
#start the service
sudo systemctl start postgres.service
#check it docker
docker ps
journalctl --no-pager -u postgres.service
sudo systemctl status postgres.service
ps aux | grep postgres
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment