I have a docker container running
> docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
c5a24953e383 gradle "bash" 22 minutes ago Up 22 minutes # naughty_torvalds
Can I duplicate this running container and run it? What is the command for it?
You can create a new image from that container using the docker commit command:
docker commit c5a24953e383 newimagename
And then start a new container from that image:
docker run [...same arguments as the other one...] newimagename
You can use:
docker run --name duplicateImage --volumes-from Image -d -p 3000:80 nginix:latest
The --volumes-from Image duplicates the 'Image' container.
So you will now have a container named Image and a container named duplicateImage and they will contain the same image that is running (a container).
Related
I pull the tensorflow/serving in docker-for-windows Linux containers
PS C:\WINDOWS\system32> docker pull tensorflow/serving
Using default tag: latest
latest: Pulling from tensorflow/serving
Digest: sha256:f7e59a29cbc17a6b507751cddde37bccad4407c05ebf2c13b8e6ccb7d2e9affb
Status: Image is up to date for tensorflow/serving:latest
docker.io/tensorflow/serving:latest
After that for any following commands the container is not listing up
PS C:\WINDOWS\system32> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
PS C:\WINDOWS\system32> docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
PS C:\WINDOWS\system32> docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
I tried restarting docker as well, may I know how to fix it?
docker pull is pulling the image you selected
You don't have a container yet.
docker ps and the other commands you used are referring to containers.
So to run the container use:
docker run {options} image
After that you be able to see the container using docker ps
When you run docker pull tensorflow/serving the Docker image will get pulled, which can be listed using docker images command.
While docker ps, docker container ls -a, docker container ls will list running docker container. You need to run your Docker image using docker run image-name then the container will get listed using the mentioned commands.
For more info on Docker, please refer this official guide.
How can I assign a name to the intermediate container that is created when building an Docker image (e.g., using docker image build)?
E.g. when I run docker build -t kaldi -f kaldi2.dockerfile ., I see that the intermediate container is assigned a random name such as "musing_mahavira".
username#server:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAME
831b257dd17c c8aa0c73486e "/bin/sh …" 2 seconds ago Up 23 seconds musing_mahavira
With docker run, one can assign a name to the container with the --name option:
username#server:~$ docker run -d --name hello kaldi
username#server:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
806df7f58a87 kaldi "bash" 3 minutes ago Up 3 minutes hello
Unfortunately, naming during the Docker container building is impossible.
To specify a name for a container use --name argument when you launch the container, or rename a running container to something more descriptive.
docker rename container_name specify_name
I have created an application that uses docker. I have built an image like so: docker build -t myapp .
While in my image (using docker run -it myapp /bin/bash to access), a image file is created.
I would like to obtain that file to view on my local as I have found out that viewing images on Docker is a complex procedure.
I tried the following: docker cp myapp:/result.png ./ based on suggestions seen on the webs, but I get the following error: Error response from daemon: No such container: myapp
Image name != container name
myapp is the name of the image, which is not a running container.
When you use docker run, you are creating a container which is based on the myapp image. It will be assigned an ID, which you can see with docker ps. Example:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
aa58c8ff2f34 portainer/portainer "/portainer" 4 months ago Up 5 days 0.0.0.0:9909->9000/tcp portainer_portainer_1
Here you can see a container based on the portainer/portainer image. It has the ID aa58c8ff2f34.
Once you have the ID of your container, you can pass it to docker cp to copy your file.
Specifying the container name
Another approach, which may be preferable if you are automating / scripting something, is to specify the name of the container instead of having to look it up.
docker run -it --name mycontainer myapp /bin/bash
This will create a container named mycontainer. You can then supply that name to docker cp or other commands. Note that your container still has an ID like in the above example, but you can also use this name to refer to it.
You could map a local folder to a volume in the image, and then copy the file out of the image that way.
docker run -it -v /place/to/save/file:/store myapp /bin/bash cp /result.png /store/
I have a mysql docker image w/ id: fb86ef4dd8b7
What is the command to build a container and name it using the above docker-image: MY_NEW_CONTAINER
"docker build -t MY_NEW_CONTAINER..." but how do I specify to use the above docker image?
A container is a running copy of an image. So to create a container from an inage, you simply docker run it.
You can give the container a name (instead of the auto-generated scientist name) with the --name option.
docker run --name mysql_container_1 fb86ef4dd8b7
Why doesn't your image have a name? You should docker tag it.
I have the following containers:
Data container which is build directly in quay.io from a github repo, basically is a website.
FPM container
NGINX container
The three of them are linked together and working just fine. BUT the problem is that every time I change something in the website (Data container) it is rebuilt (of course) and I have to remove that container and also the FPM and NGINX and recreate them all to be able to read the new content.
I started with a "backup approach" for what I'm copying the data from the container to a host directory and mounting that into the FPM and NGINX containers, this way I can update the data without restarting/removing any service.
But the idea of moving the data from the data container into the host, really doesn't like me. So wondering if there a "docker way" or a better way of doing it.
Thanks!
UPDATE: Adding more context
Dockerfile d`ata container definition
FROM debian
ADD data/* /home/mustela/
VOLUME /home/mustela/
Where data only has 2 files: hello.1 and hello.2
Compiling the image:
docker build -t="mustela/data" .
Running the data container:
docker run --name mustela-data mustela/data
Creating another container to link to the previous one:
docker run -d -it --name nginx --volumes-from mustela-data ubuntu bash
Listing the mounted files:
docker exec -it nginx ls /mustela/home
Result:
hello.1 hello.2
Now, lets rebuild the data container image, but first adding some new files, so now inside data we have hello.1 hello.2 hello.3 hello.4
docker rm mustela-data
docker build -t="mustela/data" .
docker run --name mustela-data mustela/data
If I ls /home/mustela from the running container, the files aren't being updated:
docker exec -it nginx ls /mustela/home
Result:
hello.1 hello.2
But if I run a new container I can see the files
docker run -it --name nginx2 --volumes-from mustela-data ubuntu ls /home/mustela
Result: hello.1 hello.2 hello.3 hello.4