assign port docker issue - docker

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?

Related

Docker container ps or ls doesn't show running Containers

Here is an example on my CLI:
$ docker pull hello-world
$ docker run hello-world
It shows empty when ls/ps
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
$ docker container ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
It shows up only when I use -a but it'd suggest the containers are actually not actively running.
$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96c3e42ae83a hello-world "/hello" 11 seconds ago Exited (0) 8 seconds ago jovial_rosalind
dcaed0ba308f registry "/entrypoint.sh /etc…" 42 minutes ago Created 0.0.0.0:5000->5000/tcp registry
Have I missed something?
Looks like your container exited right away. Is it meant to be interactive? (like running bash, or needing any user interaction?) if it is, you should run it like this to attach a terminal to it:
docker run -ti hello-world
If not, what does your hello program do? If it is not something that will keep running, then the container will stop whenever it exits.
Also keep in mind that, unless you pass docker run the -d/--detach flag, it will only return after the container has stopped - so if it returns right away, that means your container has already stopped.
You may want to use one of these to get a bash shell in the container to debug your problem:
docker run -ti hello-world bash
docker run --entrypoint bash -ti hello-world
To understand the difference between them, you can read the documentation on ENTRYPOINT and COMMAND.

Docker Error: No such container: friendlyhello

I'm trying to stop and remove a docker - container.
I started with docker turorial part1, now part2 from here: https://docs.docker.com/get-started/part2/#run-the-app
I copied souce from there. and its also available here: https://gist.github.com/sl5net/8b510bc0d3e00c474575e010003406c1
Here you could see how my console looks like:
Microsoft Windows [Version 10.0.16299.431]
C:\fre\private\docker\test18-05-14_05-27>docker build -t friendlyhello .
Sending build context to Docker daemon 5.12kB
no matching manifest for windows/amd64 in the manifest list entries
BTW solution: I swaped to linux container (right click>contextmenu on docker icon)
C:\fre\private\docker\test18-05-14_05-27>docker build -t friendlyhello .
... Successfully built itsdangerous MarkupSafe
Successfully tagged friendlyhello:latest
C:\fre\private\docker\test18-05-14_05-27>docker run -p 4000:80 friendlyhello
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
C:\fre\private\docker\test18-05-14_05-27>docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
friendlyhello latest 7d4d1e0f78e6 8 minutes ago 151MB
python 2.7-slim 46ba956c5967 9 days ago 140MB
C:\fre\private\docker\test18-05-14_05-27>docker container stop friendlyhello
Error response from daemon: No such container: friendlyhello
C:\fre\private\docker\test18-05-14_05-27>docker rm -f friendlyhello
Error: No such container: friendlyhello
There is no container available with the name friendlyhello as you are simply running the container using docker run -p 4000:80 friendlyhello, here friendlyhello is the name of the image, and not the container's name.
Either run that container by giving it a name like below:-
docker run -p 4000:80 --name SOMENAME friendlyhello
In this case you will be able to stop and remove that container using the below command
# container stop
docker container stop SOMENAME
# container removal
docker rm -f SOMENAME
Or if running without giving a name to the container, you will have to use the ID of the container in the commands to stop and remove, even in various other commands you will be using the ID to refer that con
The tutorial shows:
$ docker container ls
CONTAINER ID IMAGE COMMAND CREATED
1fa4ab2cf395 friendlyhello "python app.py" 28 seconds ago
You haven't added a name (tag) to your container, so you must use its ID to stop it:
docker container stop 1fa4ab2cf395
friendlyhello is the name of the image, not the container.
See docker run --name to give it a name.
If you don't have a name, you will the ID with docker ps -a
The OP adds:
using docker stop 8e008ebf3ad7 its out of list using: docker container ls buts stays in list using: docker ps -a
docker stop 8e008ebf3ad7
8e008ebf3ad7
docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
5227976cb9bb friendlyhello "python app.py" About an hour ago Up About an hour 0.0.0.0:4001->80/tcp SOMENAME
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS
PORTS NAMES
5227976cb9bb friendlyhello "python app.py" About an hour ago Up About an hour
0.0.0.0:4001->80/tcp SOMENAME
8e008ebf3ad7 friendlyhello "python app.py" 6 hours ago Exited (137) About an hour ago
That is expected: a stop will put a container in an "Exited" state, which is handy when you want to debug a container which stopped without your consent!
You can then do a docker container rm <ID> in order to reomve it from the docker ps -a list.
Note that if you had launch your container with docker run --rm ..., a stop would have stopped and removed (deleted) the container directly.
docker pull solr => to pull the docker image
docker run -p 8983:8983 -t solr => run the image and define the port
http://localhost:8983/ - run on local web browser

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

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