I was able to run a docker container but if I do sudo docker-compose up -d but how to reopen/watch the screen again if I need and close again. I am using ubuntu.
Thanks
In order to follow the logs of all of the containers that are included in the docker-compose.yml file, run the command docker-compose logs -f (probably with sudo in your case) in the same directory in which you already ran sudo docker-compose up -d. You can find more information on the command here.
You are probably looking for docker attach (documentation). Usage is:
docker attach [OPTIONS] CONTAINER
Related
I need docker-compose to run all the containers in the background.
I know, if i have one docker-compose.yaml. Then, it is go to the directory in which the configuration file is present and run:
docker-compose up -d
But, In my case, i have 3 docker-compose.yaml files in the configuration folder. And whenever, i run
docker-compose -d docker-compose.yaml up
It doesn't executes/ runs the container.
But, if i run docker-compose -f docker-compose.yaml up. Then, the docker containers will start executing on the foreground terminal.
I want these dockers to run detached from the terminal. How can i achieve that?
Docker has -d option for detached or you can use the usual & at the end of any linux command
docker-compose -f docker-compose.yaml up -d
P.s: It is a good idea to give a name to your container (specially when using -d) using the --name={some_name} so that you can easily get back to that container later using the name
Run below to command to specify docker-compose.yml file including build and send in background;
docker-compose -f docker-compose-1.yml up -d --build
This will also build new image if there are any changes in the project else it will run the same container.
I ran this command docker-compose up -d inside a directory called hosting.
How can I uninstall that image it created, so I can reinstall it.
You can remove the image by using the command:
docker rmi <image-name>:<image-version>
To list all images you can use:
docker images
You can simply again go to the hosting directory and run this:
docker-compose down
Or via -f argument specify the docker-compose file path:
docker-compose -f /path_to/hosting/docker-compose.yml down
When you use this, it stops the created containers and removes them.
Also if you want to update it, just do your work in your project (update the codes, the files and so on), then run this command to build the container:
docker-compose up -d --build
I want to see the command prompt used to trigger a python script inside a docker container. The process that is running can only be stopped if there is a dire need.
Is there any way I can see what was command line that was used?
To attach to the docker container I use this command.
docker attach [OPTIONS] CONTAINER
Thank you in advance.
You can use:
docker exec -it CONTAINER ps aux
to see the process which is running in container
You can see the docker logs for the same. sudo docker logs ContainerID/image_name:tag
rolling logs sudo docker logs -f ContainerID/image_name:tag
Each time I run the command "docker-compose run web ..." it results in another container being added to Kitematic, so that I have a list of containers like "image-name_web_run_1" and so on with each run of docker-compose.
Is this expected behaviour? If so, how do I work around it?
It is expected. You can use docker-compose run --rm to have the container removed when it exits.
You can clean up these old containers using docker-compose down or docker-compose rm -a.
Do you mean new container? That is the expected behavior for docker-compose run, see: https://docs.docker.com/compose/reference/run/
Did you mean to use docker-compose exec?
e.g., docker-compose exec web /bin/sh
See: https://docs.docker.com/compose/reference/exec/
I built a docker image from a docker file. Build said it succeeded. But when I try to show docker containers through docker ps (also tried docker ps -a), it shows an empty list. What is weird is that I'm still able to somehow push my docker image to dockerhub by calling docker push "container name".
I wonder what's going on? I'm on Windows 7, and just installed the newest version of dockertoolbox.
docker ps shows (running) containers. docker images shows images.
A successfully build docker image should appear in the list which docker images generates. But only a running container (which is an instance of an image) will appear in the list from docker ps (use docker ps -a to also see stopped containers). To start a container from your image, use docker run.
For me, docker ps -a and docker images both returned an empty list even tho I had many docker containers running. I tried rebooting system with no luck. A quick sudo systemctl restart docker fixed this "bug".
try restarting
sudo systemctl restart docker.socket
sudo systemctl restart docker
You can run the command without the -d option.
So you have the output displayed.
It may be that the application failed to start.
For me, the only thing resolving the issue is to reinstall docker. Also, one must be sure that the disk is not full.
This is the command that I use, but it may vary depending on the version of docker already installed:
apt-get install --reinstall docker.io
If prompted, choose "yes" to automatically restart docker daemon
for Linux,
at first, see all the running container
sudo docker ps
try restarting
sudo systemctl restart docker
remove previous docker image with the same name if there is any
sudo docker rm docker_container_id
once again run
sudo docker run -d --name container_name image_name
This should work
or uninstall docker and install it again
In the Dockerfile instructions, make sure the CMD commands are in between double-quotes not single-qoute
for example:
CMD [ "node" , 'index.js'] Here there is a mistake !!
Correct one is :
CMD [ "node" , "index.js"]
This mistake will make the container run and exit immediately.