I am currently trying to set up a docker container to start on boot through systemctl, but I am getting the following error in journalctl when trying to start the service:
Mar 08 14:28:22 humerus systemd[1]: Started Orthanc container.
Mar 08 14:28:22 humerus docker[9389]: Error response from daemon: No such container: vault_orthanc
Mar 08 14:28:22 humerus docker[9389]: Error: failed to start containers: vault_orthanc
Mar 08 14:28:22 humerus systemd[1]: vault_orthanc.service: Main process exited, code=exited, status=1/FAILURE
Mar 08 14:28:22 humerus systemd[1]: vault_orthanc.service: Failed with result 'exit-code'.
I am doing the following:
- Creating the docker container:
docker run --name=vault_orthanc --shm-size=2g -p 4242:4242 -p 8042:8042 vault-orthanc
Running docker ps shows:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8828f32c8411 vault-orthanc "Orthanc /etc/orthan…" 23 minutes ago Up 23 minutes 0.0.0.0:4242->4242/tcp, :::4242->4242/tcp, 0.0.0.0:8042->8042/tcp, :::8042->8042/tcp vault_orthanc
- Create the
.servicefile:
nano /etc/systemd/system/vault_orthanc.service
# File contains the following input
[Unit]
Description=Orthanc container
Requires=docker.service
After=docker.service
[Service]
Restart=always
ExecStart=/usr/bin/docker start -a vault_orthanc
ExecStop=/usr/bin/docker stop -t 2 vault_orthanc
[Install]
WantedBy=default.target
- Enable and start the service:
sudo systemctl enable vault_orthanc.service
sudo systemctl start vault_orthanc.service
And yet I get the above mentioned error message. Any help is greatly appreciated!
The logic which you are using will only work when the docker container already exist in the system memory(even though not running).
In that case, you can start container again by running
docker start -a <cont_name>command.Below is an example with prometheus container, the container was not running but was there on the host with Exited status because I had already started and stopped it once. Therefore, I was able to start it again.
However, if the container has been removed from the system, then
docker startcommand will give no such container error which is quite obvious as the container does not exist on the system and hence cannot be started. See below