Docker-compose error "failed to shutdown container" - docker

I am trying docker-compose in windows container,getting below error -failed to shutdown container: container . Looking at the container status for id 3878f34c9213, it says exited...how to find why this container exited or how to resolve this error ?
Windows 10 machine
Docker version 19.03.8
> docker-compose up Building web
Step 1/5 : FROM python:3.7-alpine
3.7-alpine: Pulling from library/python
df20fa9351a1: Pull complete 36b3adc4ff6f: Pull complete d4f879c74e1d: Pull complete 6064e23ad526: Pull complete ff64a3b3d6f3: Pull complete Digest: sha256:3bb2acc9bd988159abe35442a208895de22b76ecdbf565c636edbf01551d9905
Status: Downloaded newer image for python:3.7-alpine
---> 6ca3e0b1ab69
Step 2/5 : ADD . /code
---> 977f90bbc7d0
Step 3/5 : WORKDIR /code
---> Running in 300fbdd6e6aa
Removing intermediate container 300fbdd6e6aa
---> 5e50e300e614
Step 4/5 : RUN pip install -r requirements.txt
---> Running in 3878f34c9213
Collecting flask
Downloading Flask-1.1.2-py2.py3-none-any.whl (94 kB)
Collecting redis
Downloading redis-3.5.3-py2.py3-none-any.whl (72 kB)
Collecting Jinja2>=2.10.1
Downloading Jinja2-2.11.2-py2.py3-none-any.whl (125 kB)
Collecting Werkzeug>=0.15
Downloading Werkzeug-1.0.1-py2.py3-none-any.whl (298 kB)
Collecting click>=5.1
Downloading click-7.1.2-py2.py3-none-any.whl (82 kB)
Collecting itsdangerous>=0.24
Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting MarkupSafe>=0.23
Downloading MarkupSafe-1.1.1.tar.gz (19 kB)
Building wheels for collected packages: MarkupSafe
Building wheel for MarkupSafe (setup.py): started
Building wheel for MarkupSafe (setup.py): finished with status 'done'
Created wheel for MarkupSafe: filename=MarkupSafe-1.1.1-py3-none-any.whl size=12629 sha256=b08bae4a80da844e9226dbae27c8fa16b6273a37a4d2cb97d34829132689bdb1
Stored in directory: /root/.cache/pip/wheels/b9/d9/ae/63bf9056b0a22b13ade9f6b9e08187c1bb71c47ef21a8c9924
Successfully built MarkupSafe
Installing collected packages: MarkupSafe, Jinja2, Werkzeug, click, itsdangerous, flask, redis
Successfully installed Jinja2-2.11.2 MarkupSafe-1.1.1 Werkzeug-1.0.1 click-7.1.2 flask-1.1.2 itsdangerous-1.1.0 redis-3.5.3
ERROR: Service 'web' failed to build: The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 4294967295: failed to shutdown container: container 3878f34c9213071785a2bd0641a8490af52b5fb2607a6209c5014a33aef4ff29 encountered an error during hcsshim::System::waitBackground: failure in a Windows system call: The virtual machine or container with the specified identifier is not running. (0xc0370110): subsequent terminate failed container 3878f34c9213071785a2bd0641a8490af52b5fb2607a6209c5014a33aef4ff29 encountered an error during hcsshim::System::waitBackground: failure in a Windows system call: The virtual machine or container with the specified identifier is not running. (0xc0370110)
docker ps -a
--------------
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3878f34c9213 5e50e300e614 "/bin/sh -c 'pip ins…" 32 minutes ago Exited (4294967295) 32 minutes ago vibrant_rosalind
636cab556759 2f1fe904a562 "/bin/sh -c 'pip ins…" 39 minutes ago Exited (4294967295) 39 minutes ago silly_mclean
658dd0803e98 2f1fe904a562 "/bin/sh -c 'pip ins…" 2 hours ago Exited (4294967295) 2 hours ago bold_jackson
22bd52938931 ubuntu "/bin/bash" 13 hours ago Exited (4294967295) 13 hours ago hardcore_hertz
b56a2a9a8684 ubuntu "/bin/bash" 43 hours ago Exited (4294967295) 13 hours ago vigilant_napier
f7b70aba6f84 hello-world "cmd /C 'type C:\\hel…" 44 hours ago Exited (0) 44 hours ago brave_goldberg

When you switched to Linux containers it helped.
If you use Linux containers than you will see "Switch to Windows containers..." when you press RMB on Docker.

I had this error with docker, I uninstalled docker and installed it in another version, and it worked!

Related

Selenium not found error for docker project

I get module not found error for selinium. I installed with pip install selinium. Selenium located in : /home/admin/.local/lib/python3.8/site-packages
sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7f9aa3db selenium/standalone-firefox "/opt/bin/entry_poin…" 12 hours ago Up 17 minutes 0.0.0.0:4444->4444/tcp, :::4444->4444/tcp, 5900/tcp youtubeuploader_firefox_1
f2eb99409 hello-world "/hello" 14 hours ago Exited (0) 14 hours ago interesting_heisenberg
ls /opt/bin returns no file or directory

The container becomes different from the container created with run

When I create a container using docker run I get the expected result - a container with all the packages installed.
When I exit the container (without changing anything) and try to enter it again using docker exec, it doesn't have the packages installed.
Can Someone explain why this happens?
ubuntu#DESKTOP:~$ docker pull ciscotestautomation/pyats:latest
latest: Pulling from ciscotestautomation/pyats
Digest: sha256:7e1134ee4c7bb0d78f5aec0b71414cf1ac79026fc4757203bf29b88af24b1a03
Status: Image is up to date for ciscotestautomation/pyats:latest
docker.io/ciscotestautomation/pyats:latest
ubuntu#DESKTOP:~$ docker run --name=run_only -it ciscotestautomation/pyats:latest /bin/bash
[Entrypoint] Starting pyATS Docker Image ...
[Entrypoint] Workspace Directory: /pyats
[Entrypoint] Activating workspace
root#34db091e8cf4:/pyats# pip list
Package Version
-------------------- -----------
aiofiles 0.7.0
aiohttp 3.7.4.post0
aiohttp-swagger 1.0.15
async-lru 1.0.2
async-timeout 3.0.1
attrs 21.2.0
certifi 2021.5.30
cffi 1.14.6
chardet 4.0.0
charset-normalizer 2.0.6
cryptography 3.4.8
dill 0.3.4
distro 1.6.0
idna 3.2
idna-ssl 1.1.0
Jinja2 2.11.3
junit-xml 1.9
MarkupSafe 1.1.1
multidict 5.1.0
pathspec 0.9.0
pip 21.2.4
psutil 5.8.0
pyats 21.9
pyats.aereport 21.9
pyats.aetest 21.9
pyats.async 21.9
pyats.connections 21.9
pyats.datastructures 21.9
pyats.easypy 21.9
pyats.kleenex 21.9
pyats.log 21.9
pyats.reporter 21.9
pyats.results 21.9
pyats.tcl 21.9
pyats.topology 21.9
pyats.utils 21.9
pycparser 2.20
python-engineio 3.14.2
python-socketio 4.6.1
PyYAML 5.4.1
requests 2.26.0
setuptools 58.1.0
six 1.16.0
typing-extensions 3.10.0.2
unicon 21.9
unicon.plugins 21.9
urllib3 1.26.7
wheel 0.37.0
yamllint 1.26.3
yarl 1.6.3
root#34db091e8cf4:/pyats# exit
exit
ubuntu#DESKTOP:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34db091e8cf4 ciscotestautomation/pyats:latest "/bin/tini -- /entry…" 14 seconds ago Exited (0) 4 seconds ago run_only
ubuntu#DESKTOP:~$ docker start run_only
run_only
ubuntu#DESKTOP:~$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
34db091e8cf4 ciscotestautomation/pyats:latest "/bin/tini -- /entry…" 36 seconds ago Up 2 seconds run_only
ubuntu#DESKTOP:~$ docker exec -it run_only "/bin/bash"
root#34db091e8cf4:/pyats# pip list
Package Version
---------- -------
pip 21.1.3
setuptools 57.0.0
wheel 0.36.2
WARNING: You are using pip version 21.1.3; however, version 21.2.4 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
root#34db091e8cf4:/pyats#
When you docker run the image, you'll note the following output:
[Entrypoint] Starting pyATS Docker Image ...
[Entrypoint] Workspace Directory: /pyats
[Entrypoint] Activating workspace
There is some sort of initialization script that is activating the workspace (probably a Python virtual environment).
When you docker exec into the container, you're just starting a shell, without any initialization. You need to run whatever initialization steps are performed when the container starts.
If you docker inspect the image, you can see that the ENTRYPOINT is set to /bin/tini -- /entrypoint.sh, and if you take a look at /entrypoint.sh, you find this, which includes:
echo "[Entrypoint] Activating workspace"
source ${WORKSPACE}/bin/activate
(Where $WORKSPACE is an environment variable that will already be set in your shell.)

How to push only whats changed with Docker push?

A. Here is how I created the image:
Got latest Ubuntu image
Ran as container and attached to it
Cloned source code from git inside docker container
Tagged and pushed docker image to my registry
B. And from a different machine I pulled, changed and pushed it by doing:
Docker pull from the registry
Start container with the pulled image and attach to it
Change something in the cloned git directory
Stop container, tag and push it to registry
Now the issue I'm seeing is that every time B is repeated it will try to upload ~600MB (which is the public image layer) to the registry which takes a long time in my case.
Is there any way to avoid uploading the whole 600MB and instead pushing the only directory that has changed?
What am I doing wrong? How do you guys use docker for frequent pushes?
Docker will only push changed layers, so it looks as though something in your workflow is not quite right. It will be much clearer if you use a Dockerfile, as each instruction explicitly creates a layer, but even with docker commit the results should be the same.
Example - run a container from the ubuntu image and run apt-get update and then commit the container to a new image. Now run docker history and you'll see the new images adds a layer on top of the bash image, which has the additional state from running the APT update:
> docker history sixeyed/temp1
IMAGE CREATED CREATED BY SIZE COMMENT
2d98a4114b7c About a minute ago /bin/bash 22.2 MB
14b59d36bae0 7 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 7 months ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/ 1.895 kB
<missing> 7 months ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic 194.5 kB
<missing> 7 months ago /bin/sh -c #(nop) ADD file:620b1d9842ebe18eaa 187.8 MB
In this case, the diff between ubuntu and my temp1 image is the 22MB layer 2d98.
Now if I run a new container from temp1, create an empty file and run docker commit to create a new image, the new layer only has the changed file:
> docker history sixeyed/temp2
IMAGE CREATED CREATED BY SIZE COMMENT
e9ea4b4963e4 45 seconds ago /bin/bash 0 B
2d98a4114b7c About a minute ago /bin/bash 22.2 MB
14b59d36bae0 7 months ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0 B
<missing> 7 months ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/ 1.895 kB
<missing> 7 months ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic 194.5 kB
<missing> 7 months ago /bin/sh -c #(nop) ADD file:620b1d9842ebe18eaa 187.8 MB
When I push the first image, only the 22MB layer will get uploaded - the others are mounted from ubuntu, which is already in the Hub. If I push the second image, only the changed layer gets pushed - the temp1 layer is mounted from the first push:
> docker push sixeyed/temp2
The push refers to a repository [docker.io/sixeyed/temp2]
f741d3d3ee9e: Pushed
64f89772a568: Mounted from sixeyed/temp1
5f70bf18a086: Mounted from library/ubuntu
6f32b23ac95d: Mounted from library/ubuntu
14d918629d81: Mounted from library/ubuntu
fd0e26195ab2: Mounted from library/ubuntu
So if your pushes are uploading 600MB, you're either making 600MB changes to the image, or your workflow is preventing Docker using layers correctly.
Docker already uploads only the changed layer.
It is similar to how Docker build only rebuilds the cache invalidated layers. Of course it has to communicate with the registry which layers are available (it reports as Already pushed). And if you have changed the sequence of your operations in the Dockerfile, they are absolutely new layers and all of them will be re-uploaded obviously.
FROM ubuntu
RUN echo "hello"
EXPOSE 80
and
FROM ubuntu
EXPOSE 80
RUN echo "hello"
These two images are miles apart even though the behavioral end result is same. So take care about such things.

Docker Error when Starting an Image

I have the following Dockerfile that is supposed to start nginx server:
# Set the base image to Ubuntu
FROM ubuntu
# File Author / Maintainer
MAINTAINER myname "myemail#gemail.com"
# Install Nginx
# Add application repository URL to the default sources
# RUN echo "deb http://archive.ubuntu.com/ubuntu/ raring main universe" >> /etc/apt/sources.list
# Update the repository
RUN apt-get update
# Install necessary tools
RUN apt-get install -y nano wget dialog net-tools
# Download and Install Nginx
RUN apt-get install -y nginx
# Remove the default Nginx configuration file
RUN rm -v /etc/nginx/nginx.conf
# Copy a configuration file from the current directory
ADD nginx.conf /etc/nginx/
# Append "daemon off;" to the configuration file
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
# Expose ports
EXPOSE 80
# Set the default command to execute when creating a new container
CMD service nginx start
When I tried to start the image that I created using docker build, I get the following error:
my-MacBook-Pro:nginx-docker me$ docker run -it myname:nginx-latest
2016-07-15T12:57:00.525640076+02:00 container create 0220107a0060cf61ff7dcb601870086b4ae7a0b7cacd914d63719e9a3d0d9451 (image=myname:nginx-latest, name=sad_knuth)
2016-07-15T12:57:00.542025710+02:00 container attach 0220107a0060cf61ff7dcb601870086b4ae7a0b7cacd914d63719e9a3d0d9451 (image=myname:nginx-latest, name=sad_knuth)
2016-07-15T12:57:00.573835719+02:00 network connect 5e0b48e45380f1548ab524cfa7bfe94ae952ce740df76fda9e35561a258e31ef (container=0220107a0060cf61ff7dcb601870086b4ae7a0b7cacd914d63719e9a3d0d9451, name=bridge, type=bridge)
2016-07-15T12:57:00.654772110+02:00 container start 0220107a0060cf61ff7dcb601870086b4ae7a0b7cacd914d63719e9a3d0d9451 (image=myname:nginx-latest, name=sad_knuth)
2016-07-15T12:57:00.656973139+02:00 container resize 0220107a0060cf61ff7dcb601870086b4ae7a0b7cacd914d63719e9a3d0d9451 (height=42, image=myname:nginx-latest, name=sad_knuth, width=181)
* Starting nginx nginx [fail]
2016-07-15T12:57:00.715136152+02:00 container die 0220107a0060cf61ff7dcb601870086b4ae7a0b7cacd914d63719e9a3d0d9451 (exitCode=1, image=myname:nginx-latest, name=sad_knuth)
2016-07-15T12:57:00.757891577+02:00 network disconnect 5e0b48e45380f1548ab524cfa7bfe94ae952ce740df76fda9e35561a258e31ef (container=0220107a0060cf61ff7dcb601870086b4ae7a0b7cacd914d63719e9a3d0d9451, name=bridge, type=bridge)
my-MacBook-Pro:nginx-docker me$
EDIT:
I even tried the following as per the recommendations:
myname-MacBook-Pro:nginx-docker me$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0220107a0060 myname:nginx-latest "/bin/sh -c 'service " 8 minutes ago Exited (1) 8 minutes ago sad_knuth
7252213512f0 myname:nginx-latest "/bin/sh -c 'service " 23 minutes ago Exited (1) 23 minutes ago clever_jennings
53a5e6978978 myname:nginx-latest "/bin/sh -c 'service " 25 minutes ago Exited (1) 25 minutes ago gigantic_dubinsky
10fc9e4b749f myname:nginx-latest "/bin/sh -c 'service " 27 minutes ago Exited (1) 27 minutes ago distracted_almeida
64161feb2b2a 0d73419e8da9 "nginx -g 'daemon off" 3 hours ago Exited (1) 3 hours ago pensive_mcnulty
5c9eab4c7998 hello-world "/hello" 4 hours ago Exited (0) 4 hours ago sharp_kare
myname-MacBook-Pro:nginx-docker me$ docker container 0220107a0060
docker: 'container' is not a docker command.
See 'docker --help'.
myname-MacBook-Pro:nginx-docker me$ docker logs 0220107a0060
* Starting nginx nginx [fail]
CMD service nginx start means the main process exits immediatly after launching nginx.
You would need
CMD /usr/sbin/nginx -g "daemon off;"
To make sure it is not launched in daemon mode.
Other alternatives are here, but I prefer this one as it limits the number of processes to just nginx.

How to see the source of a DockerHub container so I can adapt it?

I want to work on a GeoDjango application that will be easy for others to work on too. I would like to use Docker to package the application.
So, a very simple question.
I can see that there is an existing GeoDjango container on DockerHub: https://registry.hub.docker.com/u/jhonatasmartins/geodjango/
How can I view the Dockerfile for this container, so that I can use it as a basis for my own container?
There is (at the moment) no way to see the Dockerfile used to generate an image, unless the author has published the Dockerfile somewhere. Images built as automated builds will have links to a source repository with a Dockerfile, but for images that were manually built and pushed you're limited to whatever folks publish in the description.
You could try contacting the image maintainer.
There are also times where doing a docker history <IMAGE_ID> could show you some tips about how the image was built. In fact, if the image was built using a Dockerfile will give you a clear image of the steps of the Dockerfile. For the ones committed from a containers you may not see some steps, but sometimes you can get some idea from there. For example for the image you said:
$ docker history jhonatasmartins/geodjango:latest
IMAGE CREATED CREATED BY SIZE
0b7e890a4644 3 months ago /bin/bash 112.2 MB
35174145916a 3 months ago /bin/bash 449.9 MB
5506de2b643b 4 months ago /bin/sh -c #(nop) CMD [/bin/bash] 0 B
22093c35d77b 4 months ago /bin/sh -c apt-get update && apt-get dist-upg 6.558 MB
3680052c0f5c 4 months ago /bin/sh -c sed -i 's/^#\s*\(deb.*universe\)$/ 1.895 kB
e791be0477f2 4 months ago /bin/sh -c rm -rf /var/lib/apt/lists/* 0 B
ccb62158e970 4 months ago /bin/sh -c echo '#!/bin/sh' > /usr/sbin/polic 194.8 kB
d497ad3926c8 4 months ago /bin/sh -c #(nop) ADD file:3996e886f2aa934dda 192.5 MB
511136ea3c5a 20 months ago 0 B
Edit1: As jwodder recommended below add --no-trunc option to docker inspect to check the complete command of each layer. I won't put here the one for the example because it's too verbose, but definitely you will get more info using it.

Resources