Rajat Gupta
Rajat Gupta

Reputation: 1959

How to restart docker container without log level?

I have a running container with log level set to JSON. I want to restart the container with log level set to none.

I tried using docker restart --log-driver none <CONTAINER_ID>, but it didn't work.

How can I restart my docker container with out log levels?

Upvotes: 0

Views: 2252

Answers (2)

Andy Shinn
Andy Shinn

Reputation: 28493

I didn't realize it was referring to --log-driver. If this is the case and you absolutely can't remove the container and start a new one, there is an option. You can manually edit the hostconfig.json file to change the logging driver and restart the Docker daemon.

Example:

I start a container that logs the date output every 10 seconds:

$ docker run -d --log-driver json-file --name mytest alpine sh -c "while true; do echo \$(date); sleep 10; done"
edf6bb60088ded11d991b6f31bc7091e2f6b81552937471beeafc5f271697a6f
$ docker logs mytest              
Mon Apr 3 21:27:08 UTC 2017
Mon Apr 3 21:27:18 UTC 2017
Mon Apr 3 21:27:28 UTC 2017

Now I stop the container:

$ docker stop mytest

Edit the hostconfig.json file (first SSH to my Docker machine):

$ docker-machine ssh default
docker@default:~$ sudo vi /mnt/sda1/var/lib/docker/containers/776d9c6d63c5e229fe4ce4bfe534f42cc9d1f04df7699171ce28414c4f086a63/hostconfig.json

Find "Type":"json-file" and change to "Type":"none" and save.

Now restart the Docker daemon (and exit SSH):

docker@default:~$ sudo /etc/init.d/docker restart
docker@default:~$ exit

Start your container again:

$ docker start mytest

No more logs:

$ docker  logs mytest
"logs" command is supported only for "json-file" and "journald" logging drivers (got: none)

Upvotes: 1

jaxxstorm
jaxxstorm

Reputation: 13261

log-level is a deprecated command, I think you mean --log-driver

You can't set the log level during restart or using docker update either, so the only way is to kill the container and start again. Hopefully you used a volume for your persistent data.

docker kill <id>
docker run --log-driver=none

Upvotes: 0

Related Questions