Docker inside Docker (without command line) [duplicate] - bash

This question already has an answer here:
Is it possible to create a docker container that contains one or more containers? [closed]
(1 answer)
Closed 6 years ago.
I want to run docker daemon inside my docker image. I know I can easily achieve this by exposing outer docker process during running my docker image, but unfortunately I have no possibility to control how my image is run. I CAN NOT use DIND.
Therefore I would like to start docker service inside either Dockerfile or some script that is my entrypoint. I tried invoking command:
CMD service docker start
after downloading and installing docker in the image and also including this command in some script start.sh and calling it:
ENRYPOINT ["path/to/script/start.sh"]
None of this worked. Is it at all possible to run docker as I want or am I doing something incorrectly or it is just not possible in my execution environment?

Per your requirements, you can't.
To run the docker service inside of a docker container, you need to modify how the container is launched to give the inner docker service privileges the outer docker service restricts by default.

I would suggest to use the DIND Container (Docker in Docker)
docker run --privileged --name some-docker -d docker:1.8-dind
Link to Docker Hub: https://hub.docker.com/_/docker/

Related

Create Docker Container from Command Fails, but Docker Desktop Succeeds

Problem
When I run the following commands the container fails to run
docker container create --name Test1 --env Var1=Val1 --env Var2=Val2 image-name:v1.0
docker start Test1
However, when I create it from Docker Desktop, it works perfectly fine.
I would like to automate some creation of containers, but commands do not appear to behave the same as running from Docker Desktop.
Is Docker Desktop including any additional arguments when creating the container that I would need to include in my command?
Additional Information
I am running a Windows Container on a Windows Computer and running the command in PowerShell.
I have also tried running the command in Command Prompt, but no luck.

Is it possible to get bash access in NOT running container?

I able to run Flask API container successfully. But during the app execution it fails and stops the container for some reason.
I do checked container logs and noticed some file missing error is coming. Now I want to debug what file is missing by accessing /bin/bash of stopped container. But it throws an error saying container is not running.
docker exec -it CONTAINER /bin/bash
Is there any workaround to access bash in the STOPPED container?
No, you cannot.
However, it might be useful to either check the logs or specify bash as an entry point when doing a docker run
Checking logs: https://docs.docker.com/config/containers/logging/
docker logs <CONTAINER_NAME>
Shell Entry point: https://docs.docker.com/engine/reference/run/#entrypoint-default-command-to-execute-at-runtime
docker run --name <CONTAINER_NAME> --entrypoint /bin/bash <IMAGE_NAME>
If you container does not have /bin/bash, try
docker run --name <CONTAINER_NAME> --entrypoint /bin/sh <IMAGE_NAME>
You can try to use the docker commit command.
From the docs:
It can be useful to commit a container’s file changes or settings into
a new image. This allows you to debug a container by running an
interactive shell, or to export a working dataset to another server.
Resource with a example:
We can transform a container into a Docker image using the commit
command. All we need to know is the name or the identifier of the
stopped container. (You can get a list of all stopped containers with
docker ps -a).
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS NAMES
0dfd54557799 ubuntu "/bin/bash" 25 seconds ago Exited (1) 4 seconds ago peaceful_feynman
Having the identifier 0dfd54557799 of the stopped container, we can
create a new Docker image. The resulting image will have the same
state as the previously stopped container. At this point, we use
docker run and overwrite the original entrypoint to get a way into the
container.
# Commit the stopped image
docker commit 0dfd54557799 debug/ubuntu
# now we have a new image
docker images list
REPOSITORY TAG IMAGE ID CREATED SIZE
debug/ubuntu <none> cc9db32dcc2d 2 seconds ago 64.3MB
# create a new container from the "broken" image
docker run -it --rm --entrypoint sh debug/ubuntu
# inside of the container we can inspect - for example, the file system
$ ls /app
App.dll
App.pdb
App.deps.json
# CTRL+D to exit the container
# delete the container and the image
docker image rm debug/ubuntu
You can't because this container is dead as well as turned down virtual machine is dead. You can check logs using docker logs command.
docker container ls -aq
docker logs <name_of_your_dead_container>
From the man pages from docker-run:
--entrypoint=""
Overwrite the default ENTRYPOINT of the image
So use something like:
docker run --entrypoint=/usr/bin/sleep 1000 ......
This will start the container and wait 1000 seconds, allowing you to connect and debug.

How do I stop my Docker Windows container from the command line?

I have a Docker Windows container that I want to stop from the command line. Seems like an easy thing to do, but the commands
docker stop my-docker-machine
and
docker kill my-docker-machine
produce the error
Error response from daemon: No such container: my-docker-machine
I've searched the following without success:
Windows Containers on Windows Server
Docker Documentation
How do I stop a docker container so it will rerun with the same command?
How do I stop my Docker Windows container from the command line?
I decided to try using the stop command with the container id instead of the name:
Docker stop ab44b99065ce
Works much better!
Edit: You might want a list of container id's first. As pointed out by Varun Babu Pozhath, you can use
docker ps to list all running containers or
docker ps -all to list all containers.

How do I run the Hetionet v1.0 docker container?

I'm trying to run the Hetionet v1.0 docker container mentioned in this SO post.
I've setup a digitalocean droplet with Docker
I ran docker pull dhimmel/hetionet and it worked
Now I run docker run dhimmel/hetionet and the following happens (and never returns to the interactive shell prompt).
If that completed successfully I think the last thing I'm supposed to do is run sh ~/run-docker.sh. Furthermore nothing is live at my droplet's ip_address:7474.
The error in the screenshot above looks a lot like it could be related to some redundant #Path("/") annotation, as described in this SO post's comment, buried in the docker container but I'm not sure.
Is the output from running docker run dhimmel/hetionet supposed to hang my shell? I'm running a 2 GB Memory / 40 GB Disk Droplet on Ubuntu 16.04 with Docker 1.12.5.
Thanks for your interest in the Hetionet Docker.
The output in 3 is expected. It looks like a Docker container successfully launched, downloaded the Hetionet database, and launched the Neo4j server. I'll look into fixing the warnings, but they're not errors, as Neo4j is still launching.
For production, we use a more advanced Docker run command. Depending on your use case, you may want to use the development docker run command:
docker run \
--publish=7474:7474 \
--publish=7687:7687 \
--volume=$HOME/neo4j/hetionet-data:/data \
--volume=$HOME/neo4j/hetionet-logs:/var/lib/neo4j/logs \
dhimmel/hetionet
Both the production and development command map ports. This will make it so the Neo4j server running inside your Docker container is available at http://localhost:7474/. This is most likely what you want. If you're doing this on DigitalOcean, you would replace http://localhost with the IP address of your droplet.
For an interactive shell session in a dhimmel/hetionet container, you can use:
docker run --interactive --tty dhimmel/hetionet bash
However, that command does not launch the Neo4j server -- it just let's you explore the image.
Does this clear things up?

How to run multiple Docker Containers in different terminals using Docker compose or with Shell?

I have to pull docker image from Docker Hub and start running multiple peers as containers.
now, I am manually opening terminal and executing my docker run command on downloaded image but I am planning to automate this process like if I/user want 2 peers to run then I should be able to provide IP Address and Port information to Docker run command and start these peers in different terminals without manual step.
After executing these commands I should be able to store these IP address and port numbers in a JSON file further transactions.
Could you please help me!!! Thanks!!
Got quick solution for the above problem.. Below is the command I have applied docker run -d IMAGE NAME /bin/bash above command runs the container in background process. Also, I am taking network credentials by applying docker inspect <Container Id>

Resources