Attach to a container generating an exception - docker

I have a docker container that is exiting prematurely due to an exception. I want to connect to it to debug the issue but I can't seem to keep it running in order to connect to it.
This is my initial run command:
docker run -p 8080:80 --env-file=Environment/secret.env --name starter1 starterapp
If I try:
docker attach starter1
It gives:
You cannot attach to a stopped container, start it first
If I try:
docker start -ai starter1
It starts but gives me the exception and exits.
If I try:
docker exec -i -t starter1 /bin/bash
I get:
Error response from daemon: Container 87ac5aade2d298c113bd31b50944b5095601eafc6fe29aebc046eacc76c5c2c9 is not running
I also tried:
docker run -it --rm starterapp /bin/bash -i
But it still dumps out after exception and doesn't open bash command prompt.
How do I get into a bash shell to debug the issue? The exception is generated from kestrel (webserver) due to a missing value so I should be able to access the bash prompt issue free I just cant keep it running so I can't attach to it.

Override the entrypoint with the --entrypoint parameter. You can do something like:
docker run -p 8080:80 -ti --env-file=Environment/secret.env --name starter1 --entrypoint /bin/bash starterapp

Related

Docker container exits after few seconds

I'm executing the following command to mount Hadoop-spark-pig-hive docker container using port mapping,
docker run -p 8088:8088 -p 50070:50070 --name hadoop-spark-pig-hive -v C:\Users\Mr.Semicolon\Desktop\iit:/resource -d suhothayan/hadoop-spark-pig-hive:2.9.2
Just to confirm it is up and running I executed the command docker ps
And it works for a few seconds only and docker container exit without any message. Please can someone suggest why this is happening and how can I solve the issue?
Note: I'm using Windows 10 Home environment and docker version 10.03.13 build 4484c46d9d
As Julien B requested I executed docker logs and got the following log message but still have no idea how to solve this,
/etc/bootstrap.sh: line 9: /usr/local/spark/conf/spark-env.sh: Permission denied
/
* Starting OpenBSD Secure Shell server sshd
...done.
Waiting for hdfs to exit from safemode
Safe mode is OFF
Started
I followed a tutorial and Following command worked for me,
docker run -it -p 8088:8088 -p 50070:50070 --name hadoop-spark-pig-hive -v C:\Users\Mr.Semicolon\Desktop\iit:/resource -d suhothayan/hadoop-spark-pig-hive:2.9.2
According to this notebook,
The -it flag tells docker that it should open an interactive container instance.

Error response from daemon: container is not running?

I am getting an error message 'Error from daemon: container is not running". Why? I started the container in detached mode, so it should be running? I tried the -it flags for interactivity but that did not work. I also tried sleeping docker but that did not work.
sh "docker run -d --name mongocontainer19"
sh "docker exec mongocontainer19 mongo mongodump"
The --name gives container names, which is mongocontainer19 in your case. So, you didn't put the image name there.
The syntax is
$ docker run [OPTIONS] IMAGE
So the command should be like$ docker run -d --name mongocontainer19 MyRedisIMAGE
--name <Your_container_alias> will be considered as an option of the command. -d or -p xx:xx are options as well.

Docker: how to to get access to interactive mode once server started in foreground?

I am running Kurento on debian through Docker with
docker run -d --name kurento -p 8888:8888 kurento/kurento-media-server
That starts the kurento server. Problem is : I need to configure /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini file that runs in docker and I have no idea on how to access it since it runs in background
When I run docker in interactive mode:
docker run -it --name kurento -p 8888:8888 kurento/kurento-media-server
the server runs in foreground, and I cannot do anything except a CTRL+C ( I tried ctrl+Z to put in in BG process)
Any idea ?
If you have to input an initial configuration file, the best way is by using a volume when starting:
docker run -d --name kurento -p 8888:8888 -v /etc/kurento/modules/kurento/:/path/to/your/env/kurento kurento/kurento-media-server
and inside /path/to/your/env/kurento will be your WebRtcEndpoint.conf.ini file
If you just want to jump inside the machine and tinker around, you can 'exec bash':
docker exec -it kurento /bin/bash
Once your container is started and running, you can create a bash session in that container with below command:
docker exec -ti <container_name> bash

running docker commands from a bash script has different results

I use the socketplane/openvswitch docker image.
When I follow their instructions to build and execute OVS commands in a running container, everything works fine. However, when I try to build a bash script for running and executing OVS commands the container returns with
db.sock: Database connection failed (Connection refused)
Actually the problem is running the following commands in a terminal:
docker run -itd --cap-add NET_ADMIN [container-name]
docker exec $cid ovs-vsctl show
succeeds, but running same commands in a bash script does not.
This is my bash script:
#!/bin/bash
cid=$(docker run -itd --cap-add NET_ADMIN [container-name])
docker exec $cid ovs-vsctl show
Thanks
My thought would be that the root of your problem is here:
docker run -itd
Because they're contradictory parameters.
-d says 'run in background`.
-it says 'run interactively, attach a tty.
So I would suggest that you try:
#!/bin/bash
cid=$(docker run -d --cap-add NET_ADMIN [container-name])
docker exec $cid ovs-vsctl show
Failing that, my second guess would be - the startup process of the container takes a little while. I get this when firing up kibana containers - it takes a few seconds to start, so I get 'permission denied' errors.
Try sticking a 'sleep' in there, as a simple test, but if that is the problem - you'll need to check the DB startup and see where you've 'got to'.
Failing that, you can "attach" to your container interactively, with docker exec -it <container> bash and run the command and troubleshoot directly.

Docker : How to run a service and a terminal in one command?

I'm running an apache server like this
docker run -d -p 80:80 php:apache /usr/sbin/apache2ctl -D FOREGROUNDD
Then I determine the name of the container with
docker ps
and execute an interactive shell on the container with
docker exec -ti hungry_fermi bash
It works well, but I would like to do the same in one command. I've tried
docker run -ti -d -p 80:80 php:apache /bin/bash -c 'bash; apache2ctl -D FOREGROUND'
The problem is that, I don't obtain a terminal and the command returns.
You're trying this:
docker run -ti -d -p 80:80 php:apache \
/bin/bash -c 'bash; apache2ctl -D FOREGROUND'
There are several problems here. First, you're using the -d command line option, which asks the docker client to detach and leave the container running. You will never get an interactive shell when using -d.
Secondly, your command -- bash; apache2ctl -D FOREGROUND -- would run bash, wait for bash to exit, then run httpd. You can instead do something like this:
docker run -ti -p 80:80 php:apache \
/bin/bash -c 'apachectl start; bash'
This would start Apache in the background (because there is no -D FOREGROUND), and then start bash...but I'm not really clear why you would want to do this, because now if you were to exit your shell the container would exit as well (taking Apache with it).
I think you are much better simply starting Apache the way you are now, and using docker exec to get a shell inside the container.

Resources