So I just updated Docker on my Mac and getting adjusted to Docker seems to be quite challenging and confusing.
A few weeks ago, I was able to mind port 8834 on the docker container to port 8834 on my local host by running the following commands (this is my command line history):
8450 docker attach -p 8834:8834 compassionate_chandrasekhar
8452 docker start -p 8834:8834 compassionate_chandrasekhar
Today, if I try to do the same thing, the following happens:
[user:test.local:]$ docker container ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
225146ec71d6 myuser/kali:kali "/usr/bin/zsh" 9 minutes ago Exited (0) 2 minutes ago agitated_fermat
e4389cac288a myuser/kali:kali "/usr/bin/zsh" 2 weeks ago Exited (255) 2 weeks ago suspicious_hypatia
265f2c9215c5 myuser/kali:kali "/usr/bin/zsh" 2 weeks ago Exited (0) 2 weeks ago hungry_poincare
34b36b4d8a7e myuser/kali:kali "/usr/bin/zsh" 2 weeks ago Created amazing_stonebraker
followed by:
[user:test.local:]$ docker start -p 8834:8834 agitated_fermat
unknown shorthand flag: 'p' in -p
See 'docker start --help'.
What am I doing wrong? Extremely confusing
Publishing ports can be done only with newly created containers not existing containers. So you need to stop the container and create a new one with the port you need
Today I was grabbing a Jenkins/Docker-tutorial, and got a similar error.
They do say to start the container the following way, but I got the same error as you:
docker run --name jenkinsci -p 8080:8080 jenkins/jenkins:lts
=> "unknown shorthand flag: 'p' in -p"
When I put the "name"-tag at the end I no longer get the error, and it downloads the container.
docker run -p 9090:8080 jenkins/jenkins:lts --name jenkinsci
It now tells me it does not recognize the option "--name"-tag after downloading.
Without "--name" the container runs.
(Tutorial link: https://medium.com/#gustavo.guss/quick-tutorial-of-jenkins-b99d5f5889f2)
Related
I tried to start a container output as follows,
I have listed all available containers using docker ps --all.
[root#sdctlt0048 express_edition]# docker ps --all
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ceb4b5256c32 store/saplabs/hanaexpress:2.00.045.00.20200121.1 "/run_hana --passwor…" 6 hours ago Exited (1) 3 hours ago express_edition
7d838bf619df 389fef711851 "echo hello" 4 days ago Exited (0) 4 days ago helloWorld
b743cad7815f portainer/portainer-ce "/portainer" 2 weeks ago Up 2 weeks 0.0.0.0:8000->8000/tcp, 0.0.0.0:9000->9000/tcp portainer
47cc21a338dd portainer/portainer "/portainer" 2 weeks ago Exited (1) 2 weeks ago youthful_maxwell
97e277d42155 hello-world "/hello" 2 weeks ago Exited (0) 2 weeks ago confident_roentgen
I entered the following commands to start the container which is in the exit stage and enter the terminal of this image.
docker start ceb4b5256c32
docker exec -it ceb4b5256c32 bach
It throws the following error.
FATA [0000] Error response from daemon: Container ceb4b5256c32 is not running
But when I start the container using docker start ceb4b5256c32. It throws the container ID out, which is okay if everything is working normally. I am not sure what caused this error.
for my docker run i was created a script where I put all my commands as follows:
Any idea on the causes and suggestions on this would be very helpful to me.
many Thank in advance.
Mb the container has already stopped when you want to execute the command?
Check if conatainer have a status Exited and logs
docker ps | grep ceb4b5256c32
docker logs ceb4b5256c32 --tail 5
If the container always stops and this is normal then try it (--rm - remove container after stopped):
docker run --rm -it <image:name> <command>
Eg:
# ~ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# ~ docker run --rm -it debian bash
root#22ce8b31b68c:/# exit
exit
# ~ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
# ~
Using an image from https://hub.docker.com/_/php.
Create and launch a hogehoge-php container with docker run -dti
% docker run -dti --name hogehoge-php php
Then I can see that the hogehoge-php container is up and running.
confirmed:
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2c9e7ff1a952 php "docker-php-entrypoi..." 6 seconds ago Up 5 seconds ago hogehoge-php
try with pull, create and start
I read that the docker run is a command that performs docker pull, docker create, and docker start all at once. So I decided to try it out as follows (I didn't do the docker pull because I already have a local php image).
% docker create --name foofoo-php php
c7687c088dda9b71d9380e9ca472afa436ac63785c1d2c195b8a08147f8adec9
% docker start foofoo-php
foofoo-php
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7687c088dda php "docker-php-entrypoi..." 16 seconds ago Exited (0) 3 seconds ago foofoo-php
When I tried as above, I got Exited (0) 3 seconds ago, and the foofoo-php container created by docker create doesn't stand up all the time.
The foofoo-php container made by docker create doesn't stand up(options not available).
% docker start -dti foofoo-php
unknown shorthand flag: 'd' in -dti
See 'docker start --help'.
The i option is available, and I was able to run it, but it doesn't leave the docker running.
% docker start -i foofoo-php
Interactive shell
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c7687c088dda php "docker-php-entrypoi..." 3 minutes ago Exited (0) 5 seconds ago foofoo-php
How can I create and start instead of run -dti?
By the way, I tried docker run without -dti
By the way, I tried docker run without -dti.
% docker run --name barbarbar-php php
Interactive shell
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6215c71a13a4 php "docker-php-entrypoi..." 15 seconds ago Exited (0) 15 seconds ago barbar-php
The container was created, but it's not standing up. I thought I should try docker start:
% docker start barbar-php
barbar-php
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6215c71a13a4 php "docker-php-entrypoi…" 33 seconds ago Exited (0) 3 seconds ago barbar-php
but the container doesn't start up.
On the other hand, stop and start a container created by docker run -dti
On the other hand, try to stop and start a container created by docker run -dti, it running up after start.
% docker stop hogehoge-php
hogehoge-php
% docker start hogehoge-php
hogehoge-php
% docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
6215c71a13a4 php "docker-php-entrypoi…" 4 minutes ago Exited (0) About a minute ago barbar-php
c7687c088dda php "docker-php-entrypoi…" 11 minutes ago Exited (0) 8 minutes ago foofoo-php
2c9e7ff1a952 php "docker-php-entrypoi…" 14 minutes ago Up 2 seconds hogehoge-php <----- Here
Behavior Summary
docker run
with dit option
up after a run
up after start
without dit option
not up after a run
not up after a start
docker create
not up after a run
What you are missing is a docker create -t to allocate a pseudo-TTY for you container.
Since the entrypoint for the image you are running is a php shell running at the foreground, the container, when started, figures out that it doesn't have a tty to attach to an exit with 0.
docker pull php
docker create -t --name hogehoge-php php
docker start hogehoge-php
I have just installed Ubuntu 20.0 and installed docker using snap. I'm trying to run some different docker images for hbase and rabbitmq but each time I start an image, it immediately exists with 126 status.
$ sudo docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d58720fce3a dajobe/hbase "/opt/hbase-server" 5 seconds ago Exited (126) 4 seconds ago hbase-docker
b7a84731a05b harisekhon/hbase "/entrypoint.sh" About a minute ago Exited (126) 59 seconds ago optimistic_goldwasser
294b95ef081a harisekhon/hbase "/entrypoint.sh" About a minute ago Exited (126) About a minute ago goofy_tu
I have tried everything and tried to use docker inspect on separate images, but nothing gives away, why the containers exit out immediately. Any suggestions?
EDIT
When i run the command i run the following
$ sudo bash start-hbase.sh
It gives the output exactly like it should
Starting HBase container
Container has ID 3c3e36e1e0fbc59aa0783a4c7f3cb8690781b2d04e8f842749d629a9c25e0604
Updating /etc/hosts to make hbase-docker point to (hbase-docker)
Now connect to hbase at localhost on the standard ports
ZK 2181, Thrift 9090, Master 16000, Region 16020
Or connect to host hbase-docker (in the container) on the same ports
For docker status:
$ id=3c3e36e1e0fbc59aa0783a4c7f3cb8690781b2d04e8f842749d629a9c25e0604
$ docker inspect $id
I think the issue might be due to some permissions, because i tried to chck the logs as suggested in the comments, and get this error:
/bin/bash: /opt/hbase-server: Permission denied
Check if the filesystem is mounted with noexec option using mount command or in /etc/fstab. If yes, remove it and remount the filesystem (or reboot).
Quick solution is restart service docker and network-manager
I have my customer Docker container on a CoreOS OS host. I start my container using the docker run command as. follows:
docker run -d --restart always --net=host -p 8080:8080 --log-opt max-size=2mb my_docker_hub_accountname/imagename
And when I reboot the host I always see multiple images being run when I run the following command:
user#coreos-1 ~ $ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4ac46db4a58c 3fa7e73d544d "java -jar /code/kec…" 7 days ago Up Less than a second lucid_aryabhata
da5392c136e9 7d996239c21c "java -jar /code/kec…" 7 days ago Up Less than a second awesome_jackson
15bcc4cfe26b 7d996239c21c "java -jar /code/kec…" 4 weeks ago Up Less than a second fervent_colden
f050f55bea3c 7d996239c21c "java -jar /code/kec…" 4 weeks ago Up Less than a second condescending_poincare
31e00707ddff 7d996239c21c "java -jar /code/kec…" 4 months ago Up Less than a second awesome_curran
user#coreos-1 ~
Is there a way to control so that I only have 1 image running instead of multiple images by the Docker container?
I was able to resolve this in one way.
I searched for all container using command:
docker ps -a
I had to remove all the other containers that were previously run using
docker rm $container_id
Now I only 1 docker image running in a container. I reboot and I only see 1 container running.
hope it helps another docker user.
i try to start two detached containers.
first a MySql
docker run -td --name mysql -p 3306:3306 -e MYSQL_PASS="admin" tutum/mysql
the i try to start a self built container for apache, typo3
docker run -td --name typo -p 80:80 --link mysql:mysql thomasm/typo3-45
i would now expect that the two containers show up in docker ps
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96607b9ee0f9 tutum/mysql:latest "/run.sh" 19 minutes ago Up 19 minutes 0.0.0.0:3306->3306/tcp mysql,typo/mysql
but both seem to be in this one container id (watch the NAMES column).
docker ps -a now shows that the "typo" container has exited
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4d5ab7351d49 thomasm/typo3-45:latest "/start.sh" 8 minutes ago Exited (0) 8 minutes ago typo
I'm a bit confused. Why does the typo name show up in the names column of the mysql container. And why does the typo container exit? I don't see any error messages. Non detached, with bash the typo container works...
output from docker logs
$ docker logs typo
* Starting web server apache2
AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.16.
Set the 'ServerName' directive globally to suppress this message
*
Why does the typo name show up in the names column of the mysql container
because they are linked together
why does the typo container exit?
You might find clues by running docker logs typo. A common mistake is to have the container run the process in the background instead of in the foreground.