I am trying to figure out why my docker service doesn't run automatically on reboot.
Here it is:
$ sudo cat /etc/systemd/system/docker.service
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --insecure-registry=some-registry
When I try:
$ sudo systemctl enable docker.service
nothing happens.
The status of this service under list-unit-files:
$ sudo systemctl list-unit-files | grep docker
docker.service static
If I start the service manually (sudo systemctl start docker.service) it works as expected though.
Any ideas why?
The issue is because you have not specified any target in your service. You should change the service file as below
$ sudo cat /etc/systemd/system/docker.service
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --insecure-registry=some-registry
[Install]
WantedBy=multi-user.target
After that run the below commands
systemctl daemon-reload
systemctl disable docker
systemctl enable docker
And restart the system
Related
everyone!
i installed docker, docker-compose, then executed next commands:
`
sudo systemctl start docker.service
sudo systemctl status docker.service
sudo systemctl enable docker.service
sudo usermod -aG docker $USER
docker run hello-world`
OS: Manjaro, Archlinux
error: Server:
ERROR: Cannot connect to the Docker daemon at unix:. Is the docker daemon running?
ALREADY TRY A LOT!! Daemon won't start!
Try export DOCKER_HOST=unix:///var/run/docker.sock, then run docker run hello-world again.
my issue's screenshot
harivinu01#penguin:~$ sudo dockerd
INFO[2022-10-11T11:09:00.045076001+05:30] Starting up
failed to start daemon: pid file found, ensure docker is not running or delete /var/run/docker.pid
harivinu01#penguin:~$
have you tried kill docker process or restart?
Delete the pid file
ps -ef | grep docker
kill -9 <PIDs>
Kill the docker service and start it again
sudo systemctl start docker.service
I have the following service defined
[Unit]
Description=Docker Compose Application Service [monitor]
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/eugenekim/Documents/monitor/node-master
ExecStart=/usr/local/bin/docker-compose -f docker-compose.log.yml up -d es-log-00
ExecStop=/usr/local/bin/docker-compose -f docker-compose.log.yml down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
The docker-compose.log.yml file has been changed and even the *.service file changed but system insists running the old definition somehow..
I've tried to run daemon-reload but it has no effect.
when I try to run
sudo systemctl reload docker-log 14469ms
Failed to reload docker-log.service: Job type reload is not applicable for unit docker-log.service.
See system logs and 'systemctl status docker-log.service' for details.
It also does not have any effect..
I think you're missing ExecReload.
[Unit]
Description=Docker Compose Application Service [monitor]
Requires=docker.service
After=docker.service
[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/eugenekim/Documents/monitor/node-master
ExecStart=/usr/local/bin/docker-compose -f docker-compose.log.yml up -d es-log-00
# docker compose will watch for changes
ExecReload=/usr/local/bin/docker-compose -f docker-compose.log.yml up -d es-log-00
# or you want a force restart
#ExecReload=/usr/local/bin/docker-compose -f docker-compose.log.yml restart es-log-00
ExecStop=/usr/local/bin/docker-compose -f docker-compose.log.yml down
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target
I have following scenario.
Two Machine ( Physical Machine)
One is Windows 10 With Docker On Windows Installer and same way ubuntu 18.04 with docker-ce installed.
I can run command on individual and that is fine.
I want to connect Ubuntu Docker Host from Docker on Windows machine. So Docker CLI on Windows Point to deamon at Ubuntu Host.
You will need to enable docker remote API on Ubuntu Docker Host by adding below settings in daemon.json or your startup script
[root#localhost ~]# cat /etc/docker/daemon.json
{
"hosts": [ "unix:///var/run/docker.sock", "tcp://0.0.0.0:2376" ]
}
Once you restart docker you can connect to docker host locally by socket file and remotely by listening port (2376).
Verify the listening port of docker on Ubuntu
[root#localhost ~]# netstat -ntlp | grep 2376
tcp6 0 0 :::2376 :::* LISTEN 1169/dockerd
Now you can connect to this docker from Windows machine by setting the DOCKER_HOST env variable in Windows like this
PS C:\Users\YellowDog> set DOCKER_HOST=tcp://<Ubuntu-Docker_Host-IP>:2376
PS C:\Users\YellowDog> docker ps
It will list docker containers running on Ubuntu Docker Host
You can also do this through additional options to the service:
Find original ExecStart line docker.service:
systemctl status docker | grep load | grep -oP "\/.+service"
# --> /lib/systemd/system/docker.service
cat /lib/systemd/system/docker.service | grep ExecStart
ExecStart=/usr/bin/dockerd -H fd:// $DOCKER_OPTS
Create a new file to store the daemon options:
sudo mkdir /etc/systemd/system/docker.service.d/
Add next lines with -H unix:// -H tcp://0.0.0.0:2375 options to /etc/systemd/system/docker.service.d/options.conf:
cat <<EOF > /etc/systemd/system/docker.service.d/options.conf
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H fd:// \$DOCKER_OPTS -H unix:// -H tcp://0.0.0.0:2375
EOF
Here you need to pay attention to the escaping $DOCKER_OPTS variable if it exists.
Or using your favorite editor, for example vim.
Now, reload the systemd daemon and restart the docker service:
# Reload the systemd daemon.
sudo systemctl daemon-reload
# Restart Docker.
sudo systemctl restart docker
Configuring your dev box to connect to the remote Docker daemon:
If you want to set DOCKER_HOST by default so it always connects remotely you can export it in your ~/.bashrc file.
Here’s an example of that as a 1 liner:
echo "export DOCKER_HOST=tcp://X.X.X.X:2375" >> ~/.bashrc && source ~/.bashrc
Or use it all at once:
DOCKER_HOST=tcp://X.X.X.X:2375 docker ps
Docker uses /var/lib/docker for storing images, how to configure docker to use /opt in centos ?
I can able to change the docker directory using following set of command's
1.Stop docker
sudo systemctl stop docker
create docker.service.d
sudo mkdir /etc/systemd/system/docker.service.d
3.create docker.conf
sudo touch /etc/systemd/system/docker.service.d/docker.conf
4.Add the docker.conf with following lines
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd --graph=/opt/docker --storage-driver=devicemapper
5.start Servicec
sudo systemctl daemon-reload
sudo systemctl start docker
Now the docker is using opt/docker instead of /var/lib/docker
You can configure docker daemon by option --graph(-g for short). In CentOS the service is managed by Systemd, you can find the link of service unit file at /etc/systemd/system/multi-user.target.wants/docker.service, or the original place /usr/lib/systemd/system/docker.service and change the ExecStart line, like:
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -g /opt
Then use systemctl daemon-reload to reload the changes, and systemctl restart docker to restart docker service.
you need to set the value of the graph parameter to your custom path, in /etc/docker/daemon.json
you can find it in:
https://docs.docker.com/v1.11/engine/reference/commandline/daemon/#daemon-configuration-file