How to configure docker to use /opt instead of /var - docker

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

Related

How to change the folder where data goes in Docker-compose?

I have a Digitalocean server (debian 11) and I want to host my nextcloud there and also other apps.
For that, I choosed the docker nextcloud way (nginx + let's encrypt).
I noticed I was almost out of disk space. So I added a volume.
Now, I want all my nextcloud data goes there, in that volume.
trying to do that i've already tried:
sudo mkdir /var/lib/docker/volumes/volume_nyc1_01
sudo vi /etc/docker/daemon.json
{
"graph": "/var/lib/docker/volumes/volume_nyc1_01"
}
sudo docker-compose down and sudo docker-compose up -d
But when i run the command docker info, still get
Docker Root Dir: /var/lib/docker
I will really appreciate it any suggestion or help
This commands were missing
sudo systemctl stop docker
sudo systemctl stop docker.socket
sudo systemctl stop container
after that I could see the root directory has changed

Docker service doesn't start after boot

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

How do i expose the Docker Remote API on Centos 7?

On ubuntu i can go into /etc/init/docker.conf and put in DOCKER_OPTS='-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock' to get the json data to display on my browser but how can i do it for Centos?
I have tried creating a file in /etc/sysconfig/docker and placing other_args="-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock" inside the file and restarting docker but it doesn't do anything.
The systemd unit installed by the Docker corp package hardcodes the command line used to start the docker daemon:
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
[...]
There is no support for reading a file from /etc/sysconfig or elsewhere to modify the command line. Fortunately, systemd gives us the tools we need to change this behavior.
The simplest solution is probably to create the file /etc/systemd/system/docker.service.d/docker-external.conf (the exact filename doesn't matter; it just needs to end with .conf) with the following contents:
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock
And then:
systemctl daemon-reload
systemctl restart docker
This is actually documented on the Docker website in this document, which includes instructions for a more flexible solution that will allow you to use files in /etc/sysconfig to control the daemon.
Yes, you can do the configuration thing. But how about a docker solution to a docker problem?
docker run -d \
--name sherpa \
-v /var/run/docker.sock:/tmp/docker.sock \
-p 2375:4550 \
djenriquez/sherpa --allow
Proxies access to the socket through port 2375 on localhost.
1、edit /usr/lib/systemd/system/docker.service to add two params in the service section:
# vim /usr/lib/systemd/system/docker.service
[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
2、reload the configuration, and then restart docker。
# systemctl daemon-reload
# systemctl restart docker
3、to check for success, see if the return the following response。
# ps -ef|grep docker
root 26208 1 0 23:51 ? 00:00:00 /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
reference from Expose the Docker Remote API on Centos 7?

Cannot change Docker image directory

I am using Fedora 22 and I must change my Docker image directory from
/var/lib/docker
to
/home/my_user/docker
Following this
How to change the docker image installation directory? I edited the /etc/sysconfig/docker adding:
other_args="-g /home/rseixas/Programs/Docker/images"
I restarted the service but no change. In fact I restarted my machine and I am not able to see it changing.
Someone can help me?
Do you have a /lib/systemd/system/docker.service file?
If so, edit it so that the Docker service uses the usual /etc/default/docker as an environment file: EnvironmentFile=-/etc/default/docker.
In the /etc/default/docker file then add DOCKER_OPTS="-g /home/rseixas/Programs/Docker/images".
At the end just do a systemctl daemon-reload && systemctl restart docker.
For further information please also have a look at the documentation.
In docker 1.8+ the service file settings changed a little:
[Service]
EnvironmentFile=-/etc/default/docker
# in docker 1.7 use ExecStart:
ExecStart=/usr/bin/docker -d $DOCKER_OPTS -H fd://
# in docker 1.8 use ExecStart:
ExecStart=/usr/bin/docker daemon $DOCKER_OPTS -H fd://
MountFlags=slave
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
& some other notes for Debian / Fedora with the latest docker & a custom directory.

How to add variable to docker daemon in CentOS?

I want to create registry mirror in docker. I read this tutorial. So,I want to add this variable "--registry-mirror=http://10.0.0.2:5000" to docker daemon when it start.
I have succeeded in mac. I add the line to /var/lib/boot2docker/profile:
EXTRA_ARGS="--registry-mirror=http://192.168.59.103:5555"
It can work after adding in mac. So I do the same thing in CentOS. I use the command in this question:I:
sudo sed -i 's|other_args=|other_args=--registry-mirror=http://<my-docker-mirror-host> |g' /etc/sysconfig/docker
sudo sed -i "s|OPTIONS='|OPTIONS='--registry-mirror=http://<my-docker-mirror-host> |g" /etc/sysconfig/docker
sudo service docker restart
and it makes my "/etc/sysconfig/docker" like below in CentOS, and this is my docker file:
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d
OPTIONS=--selinux-enabled -H fd:// -g="/opt/apps/docker"
other_args="--registry-mirror=http://10.11.150.76:5555"
Then, I restart docker using this command:
service docker restart
But, the mirror didn't work in CentOS. I use command:
ps -ef
It did't add the variable to docker daemon. what is wrong?
In the /etc/sysconfig/docker file, change:
OPTIONS=--selinux-enabled -H fd:// -g="/opt/apps/docker"
into:
OPTIONS=--selinux-enabled -H fd:// -g="/opt/apps/docker" --registry-mirror=http://10.11.150.76:5555
I can't help you with other_args, I don't know this option.
If you using yum install docker, you may get a problem with the docker service config file.
Then you need to check your system service config file, see if it using other_args as a parameter to start docker. By default, the service config file should placed at /usr/lib/systemd/system/docker.service, edit it with any editor, check ExecStart part, add other_args to it.
For example, ExecStart=/usr/bin/docker -d --selinux-enabled $other_args

Resources