docker run command hangs until the container stops - docker

I am trying to run a PPTP VPN server in a Docker container. but when I do the command docker run pptpserver, or all different container I have tried, It will work but my cursor is just flashing and does not let me do any other command.
I tried a super simple one, just copying test.sh in the container and run it, and it prints a confined times test, but I want a container that's in the background.
test.sh:
#/bin/bash
while :; do
echo "test"
sleep 2
done
The only way I can stop it is to stop the container in another terminal. Is there something I can do to just run a container like it shouts do, in the background.
# docker version
Client:
Version: 17.12.1-ce
API version: 1.35
Go version: go1.10.1
Git commit: 7390fc6
Built: Wed Apr 18 01:23:11 2018
OS/Arch: linux/amd64
Server:
Engine:
Version: 17.12.1-ce
API version: 1.35 (minimum version 1.12)
Go version: go1.10.1
Git commit: 7390fc6
Built: Wed Feb 28 17:46:05 2018
OS/Arch: linux/amd64
Experimental: false

To prevent this, you should start a container in detached mode by specifying -d=true or just -d option. If this is not specified, docker defaults to foreground mode which attaches the console to the process inside your container's standard input, output and standard error, which makes it appear as if your terminal is "hanging".
So try:
docker run -d pptpserver
You can read more about this behaviour in the Docker Run Reference documentation.

Related

Why docker container update is not stable?

I use the command docker container update --cpus 1 target_container to update the setting. But in most cases it not working and response "you must provide one or more flags when using this command", but somethings it working
Any one know the reason?
Some log is like,
$ docker container update --cpus 0.5 target_container
you must provide one or more flags when using this command
$ docker container update --cpus 0.5 target_container
you must provide one or more flags when using this command
$ docker container update --cpus 0.5 target_container
target_container
the docker version is
Client:
Version: 18.09.7
API version: 1.39
Go version: go1.10.4
Git commit: 2d0083d
Built: Fri Aug 16 14:19:38 2019
OS/Arch: linux/amd64
Experimental: false
Server:
Engine:
Version: 18.09.7
API version: 1.39 (minimum version 1.12)
Go version: go1.10.4
Git commit: 2d0083d
Built: Thu Aug 15 15:12:41 2019
OS/Arch: linux/amd64
Experimental: false
The docker update man page includes:
--cpus API 1.29+
A docker version can show you if your API is equal or above the API 29, which was with Docker 17.05.
For testing, try --cpus=1 or --cpus=0.5, considering the argument is supposed to be "number of CPUs"
As usual with commands including an hyphen: don't copy-paste it, copy it manually.

Docker cannot access any Internet URL during build

I have the following Dockerfile:
FROM mcr.microsoft.com/windows/servercore:ltsc2019
SHELL ["powershell", "-Command"]
RUN Invoke-WebRequest -UseBasicParsing http://www.google.com
On my Windows 10 machine, I run docker build . and get the following:
Basically, Docker is unable to access any Internet URL I try. I can run the same Dockerfile on my Windows Server 2019 Core machine and everything works fine. I'm running Docker version 18.09.2 and haven't updated it recently. This was working a few days ago, so it's a new issue. I've tried restarting the Docker engine and also rebooting. I've also tried a docker system prune. Any ideas what broke this? I'd rather not reinstall Docker if possible.
Docker Info:
Client: Docker Engine - Community
Version: 18.09.2
API version: 1.39
Go version: go1.10.8
Git commit: 6247962
Built: Sun Feb 10 04:12:31 2019
OS/Arch: windows/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.2
API version: 1.39 (minimum version 1.24)
Go version: go1.10.6
Git commit: 6247962
Built: Sun Feb 10 04:28:48 2019
OS/Arch: windows/amd64
Experimental: false
Update: Seems to be DNS related. I can ping things.
This is a known issue with ltsc2019 images (https://github.com/Azure/AKS/issues/1029). Put following at the start of your dockerfile or before entrypoint
Set-DnsClientServerAddress -InterfaceIndex (Get-NetAdapter).IfIndex -ServerAddresses ('8.8.8.8')

Docker Compose (docker-compose) couldn't connect to docker daemon on Windows Server 2016 TP5

I am trying to get docker-compose to work on Windows Server 2016 TP5. I have installed Docker Desktop for Windows (not Docker Toolbox) as a service, which works perfectly. I have downloaded the latest docker-compose for windows from https://dl.bintray.com/docker-compose/master/ and put it in the same path as Docker (after unblocking the downloaded file, and renaming it to docker-compose.exe.
When I run the docker-compose up (in Powershell as an Administrator), I get the following error:
ERROR: Couldn't connect to Docker daemon. You might need to install
Docker:
https://docs.docker.com/engine/installation/
Here are the docker and docker-compose information on my machine:
Docker:
Client:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 17:52:38 2016
OS/Arch: windows/amd64
Server:
Version: 1.12.1
API version: 1.24
Go version: go1.6.3
Git commit: 23cf638
Built: Thu Aug 18 17:52:38 2016
OS/Arch: windows/amd64
Docker Compose:
docker-compose version 1.9.0dev, build f65f89a
You might want to try to set your DOCKER_HOST:
$ENV:DOCKER_HOST="npipe://\\.\pipe\docker_engine"
Alternatively, when registering the engine, you can make it listen on TCP too:
dockerd.exe -H npipe:////./pipe/docker_engine -H localhost:2375 --register-service
There are more details on this Compose issue

Docker: Container command '/bin/sh' not found

When i try to build docker images using the command docker build -t opencv:2.4.11 . I get following error.
Sending build context to Docker daemon 189.8 MB
Step 1 : FROM ubuntu:trusty
---> b72889fa879c
Step 2 : RUN apt-get update
---> Running in 689f34e138c2
Container command '/bin/sh' could not be invoked.
My docker client and server version are:
Client:
Version: 1.11.0
API version: 1.23
Go version: go1.5.4
Git commit: 4dc5990
Built: Wed Apr 13 18:34:23 2016
OS/Arch: linux/amd64
Server:
Version: 1.11.0
API version: 1.23
Go version: go1.5.4
Git commit: 4dc5990
Built: Wed Apr 13 18:34:23 2016
OS/Arch: linux/amd64
Any idea?
I have softlinked my /var/lib/docker directory to one of directories present in my home. And that directory is owned by root. Is this the source of problem?
Before moving and softlinking it was fine. I ran out of space in my root partition and so I had to change it to my home partition.
And my home partition is ext4 file system.
Regards
It looks badly hosed.
I have softlinked my /var/lib/docker directory to one of directories present in my home.
I would recommend amending the daemon parameters to include -g your_other_directory instead. Then stop and restart Docker.
If it still doesn't work, delete both Docker directories, re-install, and start at the -g step again.

How to override the default value of COMPOSE_HTTP_TIMEOUT with docker-compose command

I have docker-compose which fetches some of the images and builds one.
When I run docker-compose up , I am getting the following error
ERROR: An HTTP request took too long to complete. Retry with --verbose
to obtain debug information. If you encounter this issue regularly
because of slow network conditions, consider setting
COMPOSE_HTTP_TIMEOUT to a higher value (current value: 60).
Question: How to pass the COMPOSE_HTTP_TIMEOUT with docker-compose command?
COMPOSE_HTTP_TIMEOUT is an environment variable, so
COMPOSE_HTTP_TIMEOUT=200 docker-compose up
You need your COMPOSE_HTTP_TIMEOUT at your docker instance level (docker-compose up) and not inside your docker image. So the solution is to create a .env file and put this inside:
#.env
COMPOSE_HTTP_TIMEOUT=200
you can check the doc here
For Mac users, restarting docker from the status bar icon fixed this issue:
restart the docker
command: sudo service docker restart
then try docker-compose up
I faced this issue recently. Even after overriding the default COMPOSE_HTTP_TIMEOUT value it did not work for me.
Possible cause As mentioned in documentation Compose CLI environment variables
COMPOSE_HTTP_TIMEOUT: Configures the time (in seconds) a request to the Docker daemon is allowed to hang before Compose considers it failed. Defaults to 60 seconds.
Removing the tty:true from my docker-compose worked for me.
More details on the issueCompose error "HTTP request took too long to complete" #3633
Docker Environment details:
$ docker-compose version
docker-compose version 1.18.0, build 8dd22a9
docker-py version: 2.6.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t 3 May 2016
$ docker version
Client:
Version: 18.09.1
API version: 1.39
Go version: go1.10.6
Git commit: 4c52b90
Built: Wed Jan 9 19:35:01 2019
OS/Arch: linux/amd64
Experimental: false
Server: Docker Engine - Community
Engine:
Version: 18.09.1
API version: 1.39 (minimum version 1.12)
Go version: go1.10.6
Git commit: 4c52b90
Built: Wed Jan 9 19:06:30 2019
OS/Arch: linux/amd64
Experimental: false
Add this one in .env file: COMPOSE_HTTP_TIMEOUT=1000
I had faced similar issue as below:
Quick Solution is, to restart your VM
sudo su - root
reboot -f
Then login again after 5-10 mins and check. It should work now!
Open terminal and type following command
COMPOSE_HTTP_TIMEOUT=200
To verify type
echo $COMPOSE_HTTP_TIMEOUT
Output: 200

Resources