Why can't I attach to docker container of mariadb?
$ docker run --name mariadbtest -e MYSQL_ROOT_PASSWORD=mypass -d mariadb/server:10.1
<SKIPPED>
78cadba14946919a3d62e1c616e39e76508107d24c6c1b93da534d3a3eb09e2d
$ docker attach 78cadba14946
<HANG>
How to see parameters of this container?
Also I can't ssh to the container
$ docker inspect -f "{{ .NetworkSettings.IPAddress }}" mariadbtest
172.17.0.2
$ ssh 172.17.0.2
<HANG>
docker attach <container> attaches your terminal stream to the container stdout/stderr. If the container sends nothing to these streams - you will see nothing after attaching to it. Try executing some statement in the database and see if anything appears.
As for ssh, normally containers do not have ssh in it. Use docker exec -it <container> sh instead.
Related
I have a container started as the following:
docker run --interactive --tty --gpus all --name my_container
--workdir "/home/ubuntu" --user ubuntu
--volume /hdd/all_cv/paiv/metis:/home/ubuntu/my --publish 8888:8888 my
how do I run interactively with my_container once I reboot my machine?
Based on the docker documentation, you can attach back to the detached container using docker attach command:
Use docker attach to attach your terminal’s standard input, output, and error (or any combination of the three) to a running container using the container’s ID or name. This allows you to view its ongoing output or to control it interactively, as though the commands were running directly in your terminal.
So you should try this to have an interactive session with your already running container:
docker attach my_container
If your container is stopped, you just need to start it again
docker ps -aq -f name=my_container | xargs docker start $1
How can I access the stdout & stderr of a running docker container?
When I inspect the container with docker inspect <id> | grep log I receive the following:
"LogPath": "/var/lib/docker/containers/<long id>-json.log"
But I can't find the file neither on my current folder, nor when trying to run docker exec <id> cat /var/lib/docker/containers/<long id>-json.log
edit running docker log <id> doesn’t give anything either
I am launching the container with the following command:
docker run -d -it --log-driver json-file --rm --log-opt max-size=10m --log-opt max-file=3 <my_app>
What am I missing/forgetting?
Try :
docker logs <container ID>
Is there a way to inspect a running Docker container? E.g., inspect the filesystem using a shell, etc?
To inspect an image, we could using docker run <tag> /bin/bash but I am looking to inspect a running container, not an image.
note that docker container inspect is not what I am looking for - that command just gives me metadata about the container.
Assuming that your container has a typical filesystem, you can just use docker exec to start a shell inside the container, as in:
docker exec -it mycontainer bash
Or if bash isn't available (for example, Alpine-based images):
docker exec -it mycontainer sh
Alternatively, you can export a container's filesystem as a tar archive using docker export. For example:
docker export -o mycontainer.tar mycontainer
And then you can inspect the archive or extract it as necessary. If
you just want to a file listing, then:
docker export mycontainer | tar tf -
You can use docker exec command
docker exec -it {container Id or name} command
How can do something like:
docker exec -it 06a0076fb4c0 install-smt
But use the name of the container instead
docker exec -it container/container install-smt
I am running a build on CI server so I can not manually input the container ID.
How can I achieve this?
Yes, you can do this by naming the container with --name. Note that your command with container/container is likely referencing an image name and not the container.
➜ ~ docker run --name my_nginx -p 80:80 -d nginx
d122acc37d5bc2a5e03bdb836ca7b9c69670de79063db995bfd6f66b9addfcac
➜ ~ docker exec my_nginx hostname
d122acc37d5b
Although it won't save any typing, you can do something like this if you want to use the image name instead of giving the container a name:
docker run debian
docker exec -it `docker ps -q --filter ancestor=debian` bash
This will only work if you're only running one instance of the debian image.
It does help if you're constantly amending the image when working on a new Dockerfile, and wanting to repeatedly run the same command in each new container to check your changes worked as expected.
I was able to fix this by setting a container name in the docker-compose file, and rundocker exec -it with the name form the file.
#Héctor (tnx)
These steps worked for me:
This will start the container named mytapir and spawn a shell into the docker container:
docker run -d --name mytapir -it wsmoses/tapir-built:latest bash
Upon docker ps to ensure the docker container is running:
docker exec -it mytapir /bin/bash
Will spawned a shell into an existing container named mytapir.
And you can stop the container as usual docker stop mytapir.
And starting it via docker start mytapir, if it is not running.
(check via docker ps -a)
I am trying to write to the file in /etc/hosts within a docker container when I perform the run command, but when I shh into the container and check the hosts file, nothing has been written.
What is the correct command to do this?
I am running my image with the following command:
docker run -it -p 3000:3000 <imageName> bash echo 192.168.56.101 mypath.dev >> /etc/hosts
Use the "add-host" parameter when running the container:
docker run -it --add-host db-static:86.75.30.9 ubuntu cat /etc/hosts