What does the "." in "docker run <image> . " do? - docker

I have 2 commands:
docker run -d -p 5000:8080 ${image_name} .
and
docker run -d -p 5000:8080 ${image_name}
The only difference between these two commands is the period at the end. What is the purpose of the period? I understand that it signifies the current directory, but what is its use in a command like this?

Arguments after the image name are passed to the image's entrypoint, so it depends on the default ENTRYPOINT of the image. Often, the entrypoint is bash, so running
docker run -d -p 5000:8080 ${image_name} .
Is like running bash ..
The fact that you are publishing ports in your docker run command makes me think that the image runs a server. Let's say the entrypoint of your image is python server.py. Then the command
docker run -d -p 5000:8080 ${image_name} .
is akin to running python server.py .
and the command
docker run -d -p 5000:8080 ${image_name}
is akin to running python server.py (note the absence of the dot).

Related

Ubuntu docker image is not running in the detached mode

I created one image using below Dockerfile
FROM ubuntu:latest
RUN mkdir -p /app
COPY . /app
CMD python /app/app.py
I am using this command to build the image:
DOCKER_BUILDKIT=1 docker build -t my-first-ubuntu-image .
And this one to run the container
Command for running the container : docker container run -d my-first-ubuntu-image
And when I run docker ps -a*, its status is showing Exited.
What is going on? I cannot understand because when I did the same for a nginx image, it is in running state.
There is a trick to prevent the container from dying:
docker run -d my_image -d tail /dev/null -f
The command tail /dev/null -f keeps the container busy forever.

Docker Container is not running

Please help. When I want to go into a container is says
Error response from daemon: Container 90599013c666d332ff6560ccde5053d9127e72042ecc3887550aef90fa1d1eac is not running
My DockerFile:
FROM ubuntu:16.04
MAINTAINER Anton Lapitski <a.lapitski#godeltech.com>
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD ./ /usr/src/app
EXPOSE 80
ENTRYPOINT ["/bin/sh", "-c", "/usr/src/app/entry.sh"]
Starting script - start.sh:
sudo docker build -t starter .
sudo docker run -t -v mounted-directory:/usr/src/app/mounted-directory -p 80:80 starter
entry.sh script:
echo "Hello World"
ls -l
pwd
if mountpoint -q /mounted-directory
then
echo "mounted"
else
echo "not mounted"
fi
sudo docker ps -a gives:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90599013c666 starter "/bin/sh -c /usr/src…" 18 minutes ago Exited (0) 18 minutes ago thirsty_wiles
And mosе important:
sudo docker exec -it 90599013c666 bash
Error response from daemon: Container 90599013c666d332ff6560ccde5053d9127e72042ecc3887550aef90fa1d1eac is not running
Please could you tell what I am doing wrong?
P.S adding -d flag when running not helped.
Once the ENTRYPOINT completes (in any form), the container exits.
Once the container exits, you can't docker exec into it.
If you want to get a shell on the image you just built to poke around in it, you can
sudo docker run --rm -it --entrypoint /bin/sh starter
To make this slightly easier to run, you might change ENTRYPOINT to CMD in your Dockerfile. (Docker will run the ENTRYPOINT passing the CMD as command-line arguments; or if there is no entrypoint just run the CMD.)
...
RUN chmod +x ./app.sh
CMD ["./app.sh"]
Having done that, you can more easily override the command
sudo docker run --rm -it starter /bin/sh
You can try
docker start container_id and then docker exec -ti container_id bash for a stopped container.
You cannot execute the container, because your ENTRYPOINT script has been finished, and the container stopped. Try this:
Remove the ENTRYPOINT from your Dockerfile
Rebuild the image
run it with sudo docker run -it -v mounted-directory:/usr/src/app/mounted-directory -p 80:80 starter sh
The key is the i flag and the sh at the end of the command.
I tried these two commands and it works:
sudo docker start <container_id>
docker exec -it <containerName> /bin/bash

docker ubuntu container exec bash issue

I pull & run an image like
docker run -d --name=lemp \
-v /Users/bappa/Desktop/server/www:/var/www/ \
-p 8080:80 \
stenote/docker-lemp:16.04
& then go to bash like
docker exec -it lemp bash
which is absolutely fine. But When I do with ubuntu:16.04 image same thing. I found response like below
Where is the problem? why the container exit? Thanks.
The reason that caused the different behavior is because of their Dockerfile CMD or ENTRYPOINT.
Once the main process (CMD or ENTRYPOINT) finishes, a docker container stops.
If you look at docker-lemp Dockerfile:
ENTRYPOINT ["/entrypoint.sh"]
Comparing to Ubuntu Dockerfile:
CMD ["bash"]
docker-lemp runs entrypoint.sh which runs further processes that remain in the foreground while Ubuntu runs bash that quits itself after completion.
If you want to keep Ubuntu in the background, a simple trick would be:
docker container run -d ubuntu:16.04 tail -f /dev/null
This replaces the default CMD bash with tail -f /dev/null so the container does not exits.

Alpine execute command in a new shell

I'm using an Alpine image in docker and I wanted to know if there is a command to open a new terminal and execute a command.
Like :
gnome-terminal -e <command>
I've already searched in ash man but didn't find what I wanted
You always have a choice of running commands on running containers irrespective of the OS type.
docker image pull nginx
docker container run -d --name nginx -p 80:80 nginx
docker exec -ti nginx sh -c "echo 'Hello World'"

Mariadb failure to daemonise with docker

I'm trying to use this image https://hub.docker.com/_/mariadb/ (any version).
I'm using the following to launch the container:
cd maria
docker build -t maria-image .
docker run --name maria maria-image -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1
cd ..
I'm preparing a custom build in case I need to do any future modifications so that lives in maria/Dockerfile with the following:
FROM mariadb:5.5
MAINTAINER ...
EXPOSE 3306
If I do docker ps -a I get status "Exited (2) 5 seconds ago".
Your args appear to be in the wrong order, maria-image should be after all other docker run args:
docker run --name maria -d -e MYSQL_ALLOW_EMPTY_PASSWORD=1 maria-image
The version you ran passed the -d and -e as the command for docker to run. Note that you'll want to first run docker rm -v maria to free the container name for reuse.

Resources