I build container with:
docker build -f Dockerfile.xyz -t dave/xyz .
after that I run docker with:
docker run -it \
--env='LDAP_USER=uid=bot_for_git,ou=bots,dc=company,dc=org' \
--env='LDAP_PASS=' --volume=/srv/docker/xyz/data1:/data \
-p 8010:8010 -p 9989:9989 dave/xyz
and verified that's all ok.
what is next?
My guess, that I should run docker ps, take container id from there, and to run container with the same preferences (environment, port mapping, volumes mapping) I should run:
docker start -a container_id
am I right?
And what about rebuilding image, if change Dockerfile.xyz and rebuild dave/xyz, does container with container_id get
update automatically, or I should repeat docker run -it step?
docker build [...] creates an image. You can see your images with docker images. You may give that image a specific name with the --tag=[...] option:
docker build --tag="superuser/bestimage:latest" .
docker run [...] <imageId> takes that image and starts a container. You can see active containers with docker ps (all with docker ps -a). If you used the tag above, docker run -it superuser/bestimage:latest may be used.
When you rebuild an image, a new image with a new id is created. You may see that through docker images.
does container with container_id get update automatically
No. In order to update your container, you must first remove the container with docker kill <id> and then start a new one with docker run -it <newID>.
Your initial guess
docker start -a container_id
is close but to be able to interact with the container's terminal, include the -i option, as follows:
docker start -ai container_id
Related
Here is my docker file a very simple docker file
FROM node:19-alpine
COPY package.json /app/
COPY src /app/
WORKDIR /app
RUN npm install
RUN ls
CMD [ "node", "src/index.js" ] //it has error, it should be index.js
When I try to execute docker build command it shoes the container id however docker ps does not show any containers, which means container was not launched successfully and there is problem with docker file.
the error is reported if I try to run container from docker client GUI.
How to view the errors from command line if docker file has a problem and it wasn't reported by docker build command?
docker ps only shows running containers.
If you do docker ps -a you should see the container and that it has the 'exited' status.
You can then do docker logs <container name> to see any error messages.
You need first to be clear on these two points:
1. docker file is used to build an image.
Use this command to build an image
you can also refer here
docker build -t node:test --progress=plain .
if run successly, your will get the image ID
2. but you also need to start a container based by this image.
docker run -itd --name=node-test node:test
docker ps | grep node-test
Also, check this container if or not based by your image
Hi I've got a problem with docker. I'm using it on s390x Debian, everything was working fine but now i can't start my containers. Old containers are working but when i create new container using for example: docker run ubuntu then i'm trying docker start [CONTAINER] my container don't start. When i use docker ps -a I've got all of my containers, but after when I use docker ps i can't see my new container. As you can see on scr. I created container with name practical_spence and ID 3e8562694e9f but when i use docker start, it's not starting. Please help.
As you do not specify a CMD or entrypoint to run, the default is used which is set to "bash". But you are not running the container in interactive terminal mode, so the bash just exits. Run:
docker run -it ubuntu:latest
to attach the running container to you terminal. Or specify the command you want to run in the container.
You container did start but exit instantly as it has nothing to do. You can start like this docker run -d ubuntu sleep infinity. Then use docker ps to see the running container. You can of course exec into it to do something docker exec -it <container> bash. You can stop it docker stop <container>. Re-start it docker start <container>. Finally delete (stopped) it as you don't need it anymore docker container rm <container>.
Is it difference between this commands?
docker container run -d --name moby-counter --network moby-counter -p 8080:80 russmckendrick/moby-counter
docker run -itd --name moby-counter --network moby-counter -p 9090:80 russmckendrick/moby-counter
In addition then why in second command uses -i(Interactive) and -t(TTY)?
docker container run is equivalent to docker run, as well as nearly all docker container commands can be found without container subset.
About -it. t creates console (tty), and i forwards your input to docker. That means you can use -t when you just need to observe the output, but you need both when container expects some input from you.
I have two containers running on a host. When I'm in container A I want to run a diff on container B compared to it's image to see what has changed in the filesystem. I know this can be ran easily from the host itself, but I'm wondering is there any way of doing this from inside container A, to see the difference on container B?
You can run any docker commands from within container which will communicate with host docker daemon if:
You have access to docker socket inside container
You have docker client inside container
You can achieve first condition by mounting docker socket to container - add following to your docker run call:
-v /var/run/docker.sock:/var/run/docker.sock.
The second condition depends on your docker image.
If you are running bare Ubuntu image you can have shell inside container which will be able to do what you want with following command:
docker run -it -v /var/run/docker.sock:/var/run/docker.sock ubuntu:latest sh -c "apt-get update ; apt-get install docker.io -y ; bash"
I am a Docker-newbie and I've got a project from another developer including a Dockerfile. This shall give me the Virtual Machine to continue work with the (nodeJS-) project inside this project folder.
Docker is already installed on my machine.
How can I launch this container now?
I've read about a command
sudo docker run -name my_first_instance
but i can't find any container name in the Dockerfile.
The dockerfile will create an image for you that you can launch containers from. this being said , Follow this:
Create a folder.
Copy dockerfile in the folder
cd into the folder execute the following command:
docker build -t <your desired image name> .
This will create an image using directives in the dockerfile in the current folder.
Now launch a container from the image.
docker run -d --name <your container name> <imagename from previous step> <optional startup commands>
Useful docker commands:
You can expose ports in the previous command using -p switch.
You can list Images via docker images
You can list running containers via docker ps
you can list running + exited containers via docker ps -a
have a look at
https://hub.docker.com/_/node/
it is the official repository for NodeJS docker images
If you want some docker images based on NodeJS, you will need to pull them docker pull my_node_image
Then you can launch one with such a command
docker run -it --rm --name my-running-script -v "$PWD":/usr/src/app -w /usr/src/app node:4 node your-daemon-or-script.js
The Dockerfile is just the recipe to build a docker image, for Nginx, Mysql, MongoDb, Redis, Wordpress, Spotify, atop, htop...
If docker images shows nothing, it means you have not yet pulled any docker image.