NAMES column of "docker ps" output [duplicate] - docker

This question already has answers here:
Container NAMES when deploying with Docker
(2 answers)
Closed 2 years ago.
Below is the docker file:
FROM golang:1.14.10
MAINTAINER xyz
ENV SOURCES /product-api
COPY . ${SOURCES}
WORKDIR /product-api
RUN make swagger
ENTRYPOINT product-api
After running the below commands:
$ docker build -t cloud-native-product-api:1.0.0
$ docker run -it -p 8080:8080 cloud-native-product-api:1.0.0
docker ps gives below output:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9aa144b7873c cloud-native-product-api:1.0.0 "/bin/sh -c product-…" 3 minutes ago Up 3 minutes 0.0.0.0:9090->9090/tcp trusting_matsumoto
Where does value trusting_matsumoto derive from in NAMES column?

Unless you specify a name for the container, docker assigns a random one.
You can specify a container name by using the --name argument:
$ docker run --rm -it --name my_alpine_container alpine
From the documentation
If you do not assign a container name with the --name option, then the daemon generates a random string name for you. Defining a name can be a handy way to add meaning to a container. If you specify a name, you can use it when referencing the container within a Docker network. This works for both background and foreground Docker containers.

Related

Inspect docker container at container startup [duplicate]

This question already has answers here:
Explore Docker's image files if container exits immediately?
(3 answers)
Closed 3 years ago.
I downloaded an image which immediately stops. How can I inspect it (or any container spawned from it)?
I cannot use anything like docker exec -it CONTAINER_ID bash since I don't have time to get the CONTAINER_ID.
(docker run -it 5413e661e579 bash does not help, it starts the container and stops immediatly.)
I don't know how the image was built, I don't have the Dockerfile ; the only thing I know is the entrypoint: ["python" "app.py"] but it does not output anything useful.
Answer from duplicate question:
docker run -it --entrypoint "/bin/bash" image_name
You can get the container id by passing in the --all flag to docker container ls
docker container ls --all
This will list all containers, including those that have been stopped or exited. Then, once you have the container id, inspect the logs with the docker logs command
docker logs <container>

Create new image based on standard one

I have installed Docker and have running some Ubuntu image with command:
sudo docker run ubuntu
I would like to create some text file on it and find it next time the same image will run. How to achieve that?
UPD.
Got problems with attaching to docker.
I have running docker
docker ps -a
aef01293fdc9 ubuntu "/bin/bash" 6 hours ago Up 6 hours priceless_ramanujan
Since it is Up mode, I suppose I don't need to execute command:
docker start priceless_ramanujan
So, I run command attach
docker attach priceless_ramanujan
And got nothing in output while command not returns.
Why I can't get to container's bash?
Simple example:
$ docker run -it ubuntu
root#4d5643e8c1a8:/# echo "test" > test.txt
root#4d5643e8c1a8:/# cat test.txt
test
root#4d5643e8c1a8:/# exit
exit
$ docker run -it ubuntu
root#cdb44750bffc:/# cat test.txt
cat: test.txt: No such file or directory
root#cdb44750bffc:/#
docker run image_name
This command creates and starts a new container based on the provided image_name. If a name is not set for the container, a random one is generated and assigned by docker. In the above example 2 containers were created based on ubuntu.
with docker ps -a we can see that modest_jennings and optimistic_leakey are the random names created:
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cdb44750bffc ubuntu "/bin/bash" About a minute ago Exited (1) 4 seconds ago optimistic_leakey
4d5643e8c1a8 ubuntu "/bin/bash" 2 minutes ago Exited (0) 2 minutes ago modest_jennings
cat test.txt failed the 2nd time because the file didn't exist. The container started from a "clean" ubuntu image.
Actually, we created test.txt inside modest_jennings only.
docker start container_name
This command starts a stopped container. So, in our case, the file is still there:
$ docker start modest_jennings
modest_jennings
$ docker attach modest_jennings
root#4d5643e8c1a8:/# cat test.txt
test
root#4d5643e8c1a8:/#
docker commit container_name image_name
This command is to create a new image, so that you can use it later and run containers based on that image. Continuing our example...
$ docker commit modest_jennings my_ubuntu
sha256:a4357f37153ac0b94e37315595f1a3b540538283adc3721df4d4e3b39bf8334f
$ docker run -it my_ubuntu
root#2e38616d532a:/# cat test.txt
test
root#2e38616d532a:/#
If you want a custom image, you can create a Dockerfile
`FROM ubuntu:16.04
ADD ./test.txt /tmp/`
after you can build it docker build -t ubuntu:custom .
and finally run your custom image docker run --name myubuntu ubuntu:custom sleep 3000
You can check your file with docker exec -it myubuntu /bin/bash and more /tmp/test.txt

assign port docker issue

I am assigning port to my docker Image to run in browser but when I am assigning to port It gives me error like
by executing this command
docker run -d -P 86:5000 secondphp2
> Unable to find image '86:5000' locally docker: Error response from
> daemon: repository 86 not found: does not exist or no pull access. See
> 'docker run --help'.
This is my docker file
FROM php:7.0-apache
COPY / C:\wamp64\www\test
EXPOSE 86
I have successfully created Image with the name of secondphp2, I know that because when I run this command docker ps -a It gives me response like
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe1840c962c4 secondphp2 "/bin/bash" 2 days ago Exited (0) 2 days ago sleepy_bose
Is there something I am missing or any clue for me to solve this Issue?
EDIT
First I have created docker Image file from above docker file by using this command
docker build -t secondphp2 .
after running this command Image was successfully created
REPOSITORY TAG IMAGE ID CREATED SIZE
secondphp2 latest 7968d546d5fd 2 days ago 346 MB
Try:
docker run -d -p 86:5000 secondphp2
The -P (upper case) is not a valid flag. To expose port use -p in lower case.
The order of arguments passed to docker matters:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
OPTIONS: -p 86:5000 and -d are options.
IMAGE: secondphp2
ARG: Arguments passed to be executed on the image (for example: /bin/sh -l)
I'm not allowed to comment on your post, but the error it gives, makes me assume that you're not using the correct syntax when starting your docker.
The docker agent is apparently trying to find version 5000 of an image named 86.
Can you show us what you're running to start the docker?

How can I map a volume in a running docker container?

I am running jenkins docker container. how can keep jenkins backup folder in my current OS ?
You need to use -v flag in docker run this way:
docker run -v /Users/<path>:/<container path>
This will map your /Users/ directory to the container directory specified.
You can find more information here: https://docs.docker.com/engine/tutorials/dockervolumes/
First of all, you need to create a new image from the running container :
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c3f279d17e0a jenkins:latest "/bin/bash" 7 days ago Up 25 hours jenkins
$ docker commit jenkins newjenkinsimage:v2
This image takes the exact same state as the running container, check the result with the following command :
$ docker images
REPOSITORY TAG ID CREATED SIZE
newjenkinsimage v2 f5283438590d 16 seconds ago 335.7 MB
Finally you need to run a new container from the new image and mount a volume :
$ docker run -it --name newjenkins -v /path/to/backup/file:/backup newjenkinsimage:v2
PS : for the -v argument, The format is host-src:container-dest

Docker run appears to ignore the name argument

I've built a docker image based on some Dockerfile that I have written.
docker build -t someuser/somerepo:sometag .
But when I run this image with a name attribute it's apparently ignored.
docker run -t someuser/somerepo:sometag -d --name="somename"
Docker ps then gives;
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a0225d20fddf someuser/somerepo:sometag "/bin/sh -c '/usr/lo 26 seconds ago Up 26 seconds 8600/tcp, 8600/udp tender_curie
Where the name assigned follows dockers random name generator.
The image itself is working as intended and seems to be doing its thing. This is seemingly trivial, I know, but I just can't make the running container accept a name. I've tried as many variations of "--", in/excluding the equal sign, different quote characters etc as I can think of.
So the question is; what I am doing wrong?
Thanks.
look at the syntax of the run command: http://docs.docker.com/reference/run/
docker run [OPTIONS] IMAGE[:TAG] [COMMAND] [ARG...]
[options] go before IMAGE
so you should try
docker run -t -d --name="somename" someuser/somerepo:sometag

Resources