Docker compose no response - docker

After docker-compose down and docker-compose up several times, sometime docker-compose up will cause no response. Normally, docker will tell you what container is created. But, nothing is shown. I try to quit Docker App and restart it. Cannot fix it. After restart OS, then docker-compose works fine.
Anyone know this issue?
Update:
Docker version: 1.12.0, build 8eab29e
Docker Composer Version: 1.8.0, build f3628c7
Platform: MacOS 10.11.4

You might need to run docker-compose ps to see what is currently running. If I were you I would like to kill the ps by running docker-compose kill and docker-compose rm. Atm the docker compose will be clean and you could run docker-compose up again

Finally, i found the core issue. For my environment, i use Charles as proxy server. I enable the Mac OS proxy in Charles. Once, i disable it. Docker will work fine.

Follow documentation on link:
https://docs.docker.com/compose/install/
I used on Ubuntu 16.04 command:
curl -L https://github.com/docker/compose/releases/download/1.14.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
After that check if it works. Output should looks like:
$ docker-compose --version
docker-compose version 1.10.1, build b252738

Related

how to reopen a docker container window again

I was able to run a docker container but if I do sudo docker-compose up -d but how to reopen/watch the screen again if I need and close again. I am using ubuntu.
Thanks
In order to follow the logs of all of the containers that are included in the docker-compose.yml file, run the command docker-compose logs -f (probably with sudo in your case) in the same directory in which you already ran sudo docker-compose up -d. You can find more information on the command here.
You are probably looking for docker attach (documentation). Usage is:
docker attach [OPTIONS] CONTAINER

Docker desktop mac wont update docker compose

I updated docker desktop for Mac (intel) this morning to Docker Desktop 4.9.1. My docker compose version won't seem to update. When I run docker-compose --version in my terminal it returns docker-compose version 1.25.5, build unknown. I tried installing docker-compose with brew and after some tinkering I got confirmation that it installed version 2.6.0, however after restarting docker desktop and my computer, I still get 1.25.5 when I run docker-compose --version.
How can I force docker to use a newer version of docker-compose?
NOTE: In my docker-compose.yml file I have version 2 running.
My docker compose also came via Docker Desktop on MacOS and it did not update/had the latest the latest version of docker-compose. I resolved this by installing docker-compose via brew:
https://formulae.brew.sh/formula/docker-compose
brew install docker-compose
Don't forget to follow the after-install instructions:
"Compose is now a Docker plugin. For Docker to find this plugin, symlink it:"
mkdir -p ~/.docker/cli-plugins
ln -sfn /opt/homebrew/opt/docker-compose/bin/docker-compose ~/.docker/cli-plugins/docker-compose
The only way I was able to solve this was to completely manually uninstall docker desktop and all docker related items from brew. I deleted every docker file I could find from my lib and then reinstalled.

docker-compose v3.7. How to give access to GPU for service

I have docker-compose.yml file with configuration of my application.
One of the services needs access to the GPU.
I built the container separately and using the command docker run -it --gpus=all <my_image> /bin/bash quite simply started everything.
But I need to start this service with GPU access using docker-compose.
Version of my docker-compose.yml - 3.7
And if I use the code examples from the official documentation, then they do not work, for example these one:
services:
test:
image: tensorflow/tensorflow:latest-gpu
command: python -c "import tensorflow as tf;tf.test.gpu_device_name()"
deploy:
resources:
reservations:
devices:
- capabilities: [gpu]
docker-compose throws an error on the keyword reservations
Please tell me how can I give access to the GPU for my service with docker-compose.yml version 3.7
Check the version of your docker-compose >= 1.28, I had a similar issue and updating solved it for me.
From the documentation:
Docker Compose v1.28.0+ allows to define GPU reservations
You can check the documentation for how to install docker-compose. Yet, here is what worked for me:
Check your version (to make sure this is the issue)
$ docker-compose --version
docker-compose version 1.25.0, build unknown
The version should be at least 1.28. Then you can install the latest by running the following comands:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Start a new terminal and check for the version again:
$ docker-compose --version
docker-compose version 1.29.2, build 5becea4c

Docker-compose does not install or run properly on boot2docker

I have successfully installed docker-machine on my Windows computer, and I'm able to use the Docker CLI on my windows box to run docker commands on a boot2docker VM.
I have docker-machine version 0.2.0, and docker 1.6.2, and the VM yields "4.0.3-boot2docker" when I run "uname -r" on it.
Now I want to install docker-compose to manage that boot2docker VM. Does docker-compose run on my Windows machine and manage the VM "remotely", as docker does, or do I have to install it on the VM itself?
On a related note, I tried installing docker-compose on my VM by doing the following:
C:\ docker-machine ssh dev
$ whoami
docker
$ sudo -i
# curl -L https://github.com/docker/compose/releases/download/1.2.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
# chmod +x /usr/local/bin/docker-compose
# exit
$ which docker
/usr/local/bin/docker
$ which docker-compose
/usr/local/bin/docker-compose
This is fine, but when I try to run docker-compose it doesn't work.
$ docker-compose up
-sh: docker-compose: not found
The file is in /usr/local/bin, and it has exactly the same privileges as docker.
docker#dev:/usr/local/bin$ ls -al do*
-rwxr-xr-x 1 root root 15443675 May 13 21:24 docker
-rwxr-xr-x 1 root root 5263681 May 19 00:09 docker-compose
docker#dev:/usr/local/bin$
Is there something I'm missing?
Have a good look at the curl output. It seems that the download url is not valid anymore. I found that
curl -L https://github.com/docker/compose/releases/download/1.2.0/docker-compose-Linux-x86_x64
gave
{"error":"Not Found"}
For me, the current release 1.3.2 worked well, i.e.:
curl -L https://github.com/docker/compose/releases/download/1.3.2/docker-compose-Linux-x86_x64
NOTE: When using on current CoreOS don't try to output in /usr/local/bin/docker-compose as noted here. Instead use /opt/bin/docker-compose (dir may need to be created first), i.e.
mkdir -p /opt/bin
curl -L https://github.com/docker/compose/releases/download/1.3.2/docker-compose-Linux-x86_x64 > /opt/bin/docker-compose
I found that the download links don't work for older versions and the "install" fails silently resulting in the problem you describe. Have a look to find a download link to a current version here:
https://github.com/docker/compose/releases
Like mkoertgen said, you can always view the output from the curl command in the terminal to see that you don't get "not found" or something similar or run cat /usr/local/bin/docker-compose to verify that it's not a textfile containing "not found".
You can install docker-compose on your Windows host too.
It will manage your docker remotely. You can think of docker-compose as a more abstract interface to docker.
After running boot2docker init, run boot2docker shellinit | Invoke-Expression. This will tell docker and docker-compose where the docker server is running.
More info on installing it on Windows can be found here: http://docs.docker.com/installation/windows/

How to make sure docker's time syncs with that of the host?

I have dockers running on Linode servers. At times, I see that the time is not right on the dockers. Currently I have changed the run script in every docker to include the following lines of code.
yum install -y ntp
service ntpd stop
ntpdate pool.ntp.org
What I would ideally like to do however is that the docker should sync time with the host. Is there a way to do this?
The source for this answer is the comment to the answer at: Will docker container auto sync time with the host machine?
After looking at the answer, I realized that there is no way a clock drift will occur on the docker container. Docker uses the same clock as the host and the docker cannot change it. It means that doing an ntpdate inside the docker does not work.
The correct thing to do is to update the host time using ntpdate
As far as syncing timezones is concerned, -v /etc/localtime:/etc/localtime:ro works.
You can add your local files (/etc/timezone and /etc/localtime) as volume in your Docker container.
Update your docker-compose.yml with the following lines.
volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
Now the container time is the same as on your host.
This will reset the time in the docker server:
docker run --rm --privileged alpine hwclock -s
Next time you create a container the clock should be correct.
Source: https://github.com/docker/for-mac/issues/2076#issuecomment-353749995
If you are using boot2docker and ntp doesn't work inside the docker VM (you are behind a proxy which does not forward ntp packets) but your host is time-synced, you can run the following from your host:
docker-machine ssh default "sudo date -u $(date -u +%m%d%H%M%Y)"
This way you are sending your machine's current time (in UTC timezone) as a string to set the docker VM time using date (again in UTC timezone).
NOTE: in Windows, inside a bash shell (from the msys git), use:
docker-machine.exe ssh default "sudo date -u $(date -u +%m%d%H%M%Y)"
This is what worked for me with a Fedora 20 host. I ran a container using:
docker run -v /etc/localtime:/etc/localtime:ro -i -t mattdm/fedora /bin/bash
Initially /etc/localtime was a soft link to /usr/share/zoneinfo/Asia/Kolkata which Indian Standard Time. Executing date inside the container showed me same time as that on the host. I exited from the shell and stopped the container using docker stop <container-id>.
Next, I removed this file and made it link to /usr/share/zoneinfo/Singapore for testing purpose. Host time was set to Singapore time zone. And then did docker start <container-id>. Then accessed its shell again using nsenter and found that time was now set to Singapore time zone.
docker start <container-id>
docker inspect -f {{.State.Pid}} <container-id>
nsenter -m -u -i -n -p -t <PID> /bin/bash
So the key here is to use -v /etc/localtime:/etc/localtime:ro when you run the container first time. I found it on this link.
Hope it helps.
This easy solution fixed our time sync issue for the docker kernel in WSL2.
Open up PowerShell in Windows and run this command to resync the clock.
wsl -d docker-desktop -e /sbin/hwclock -s
You can then test it using
docker run -it alpine date
Reference: https://github.com/docker/for-win/issues/10347#issuecomment-776580765
I have the following in the compose file
volumes:
- "/etc/timezone:/etc/timezone:ro"
- "/etc/localtime:/etc/localtime:ro"
Then all good in Gerrit docker with its replication_log set with correct timestamp.
If you're using docker-machine, the virtual machines can drift. To update the clock on the virtual machine without restarting run:
docker-machine ssh <machine-name|default>
sudo ntpclient -s -h pool.ntp.org
This will update the clock on the virtual machine using NTP and then all the containers launched will have the correct date.
I was facing a time offset of -1hour and 4min
Restarting Docker itself fixed the issue for me.
To set the timezone in general:
ssh into your container:
docker exec -it my_website_name bash
run dpkg-reconfigure tzdata
run date
docker-compose usage:
Add /etc/localtime:/etc/localtime:ro to the volumes attribute:
version: '3'
services:
a-service:
image: service-name
container_name: container-name
volumes:
- /etc/localtime:/etc/localtime:ro
It appears there can by time drift if you're using Docker Machine, as this response suggests: https://stackoverflow.com/a/26454059/105562 , due to VirtualBox.
Quick and easy fix is to just restart your VM:
docker-machine restart default
For docker on macOS, you can use docker-time-sync-agent. It works for me.
With docker for windows I had to tick
MobyLinuxVM > Settings > Integration Services > Time synchronization
in Hyper-V manager and it worked
Windows users:
The solution is very simple. Simply open a powershell prompt and enter:
docker run --privileged --rm alpine date -s "$(Get-Date ([datetime]::UtcNow) -UFormat "+%Y-%m-%d %H:%M:%S")"
To check that it works, run the command:
docker run --rm -it alpine date
My solution is inspired by something I found in docker forum thread. Anyways, it was the only solution that worked for me on docker desktop, except for restarting my machine (which also works). Here's a link to the original thread: https://forums.docker.com/t/syncing-clock-with-host/10432/23
The difference between the thread answer and mine is that mine converts the time to UTC time, which is necessary for e.g. AWS. Otherwise, the original answer from the forum looks like this:
docker run --privileged --rm alpine date -s "$(date -u "+%Y-%m-%d %H:%M:%S")"
Although this is not a general solution for every host, someone may find it useful. If you know where you are based (UK for me) then look at tianon's answer here.
FROM alpine:3.6
RUN apk add --no-cache tzdata
ENV TZ Europe/London
This is what I added to my Dockerfile ^ and the timezone problem was fixed.
Docker Usage
Here's a complete example which builds a docker image for a go app in a multistage build. It shows how to include the timezone in your image.
FROM golang:latest as builder
WORKDIR /app
ENV GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
COPY go.mod .
COPY go.sum .
RUN go mod download
COPY . .
RUN go build -a -installsuffix cgo -ldflags '-extldflags "-static"' -o main
### Certs
FROM alpine:latest as locals
RUN apk --update --no-cache add ca-certificates
RUN apk add --no-cache tzdata
### App
FROM scratch
WORKDIR /root/
COPY --from=locals /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
COPY --from=builder app/main .
COPY --from=builder app/templates ./templates
COPY --from=locals /usr/share/zoneinfo /usr/share/zoneinfo
ENV TZ=Asia/Singapore
EXPOSE 8000
CMD ["./main"]
For me, restarting Docker Desktop did not help. Shutting down Win10 and start it again, it did help.
I saw this on windows, launching Prometheus from docker-compose. I had a 15 hour time drift.
If you are running Docker Desktop on WSL, you can try running wsl --shutdown from a powershell prompt.
Docker Desktop should restart, and you can try running your docker container again.
Worked for me, and I didn't have to restart.
I've discovered that if your computer goes to sleep then the docker container goes out of sync.
https://forums.docker.com/t/time-in-container-is-out-of-sync/16566
I have made a post about it here
Certificate always expires 5 days ago in Docker
Enabling Hyper-V in Windows Features solved the problem:
Windows Features
For whatever reason none of these answers solved my problem.
It had nothing to do with the docker date/time for the images I was creating. It had to do with my local WSL date time.
Once I ran sudo ntpdate-debian everything worked.
If you don't have ntp just install it and run the command. If you aren't using debian then you probably won't have the shell script ntpdate-debian, but you can use ntpd -gq as well. Basically just update the date for your main WSL distro.
This code worked for me
docker run -e TZ="$(cat /etc/timezone)" myimage

Resources