I have a MySQL instance running on a docker container. I am trying to access the bash terminal by running "docker exec -t myContainerID /bin/bash" for the container so that I can check into my MySQL and see if the setup is correct. Although after accessing the bash terminal, any command I run is irresponsive. Even something as simple as ls. Is there any way to resolve this or know what might be causing the problem? Thanks.
You seem to be missing the -i option, try running: docker exec -ti CONTAINER_ID /bin/bash
And just FYI:
--interactive , -i Keep STDIN open even if not attached
--tty , -t Allocate a pseudo-TTY
Related
I'm just using docker for first time and I copy it on the internet
This is my file
Dockerfile
FROM mysql:oracle
COPY dbscript.sql /docker-entrypoint-initdb.d/
and I build it with this command
docker build -t mysqllab
after built I run it
docker run -d --name mysqllabtest -e MYSQL_ROOT_PASSWORD='abc123' mysqllab
it's run and get the message of container id, so I run
docker ps
to see what my container is running but it's don't have this container, I try it again with fast docker ps so I see it run for 4 seconds and terminate
What Can I do with this?
I just use
docker logs mysqllabtest
for check something wrong it about MySQL script so after I edited it It's works! thanks #Hans Kilian for tell me this command
I am not able to exec into container which uses containerd as runtime.
I need to check some processes running inside the container. Is there any way to exec into container?
I am able to list containers using ctr cli.
Any help would be appreciated.
exec is a sub-command of command task,try
ctr -a $CONTAINERD_HOST -n $NAMESPACE t exec -t --exec-id $exec_id --fifo-dir /tmp $executor_id bash
An alternative to the ctr command that K D Singh wrote about is crictl, so you can use it like so
crictl exec -it 9b47589560c6d /bin/sh
where 9b47589560c6d would be replaced by your container id (doesn't work with names as far as I know).
Firstly run to learn container id:
sudo crictl ps -a
Be careful to use container id (first three letters enough):
sudo crictl exec -it 27e /bin/sh
With ctrctl, we can give seperate commands for images, container and pod (like rmi: remove image, rmp: remove pod, rm: remove container)
Commands: https://github.com/kubernetes-sigs/cri-tools/blob/master/docs/crictl.md
You can use exec command
docker exec -it <container name> /bin/sh
The -i option keeps the STDIN open and -t allocates a pseudo-tty
This will open the shell and you can execute any command inside the running container.
Use exec command for containerd
ctr containers exec -h
Reference:
https://chromium.googlesource.com/external/github.com/docker/containerd/+/refs/tags/v0.2.7/docs/cli.md#exec-another-process-into-a-container
I am trying to achieve something like
docker run -it <image_name> bash
I want to specify the image to run and do not care about anything else.
crictl requires config files for both a container and a pod for the run command, if I am not mistaken.
[hbaba#ip-XX-XX-XXX misc]$ sudo crictl -r /run/crio/crio.sock run -h
....
USAGE:
crictl run [command options] container-config.[json|yaml] pod-config.[json|yaml]
I am looking for the simplest way of starting a container, possibly with only a specified image.
Goal: Currently trying to connect to a MySQL database on the host from the container.
Action: I have seen several answers to this problem, one being to run the container in host only mode with the --net=host option, so I can access the host using localhost/127.blah.
Result: Normally, when I execute the command
docker run -it [image_id] bash
I get a shell prompt with [user]#[container_id] (i.e., username#12345abcdef). However, when I execute the command
docker run --net=host -it [image_id] bash
it drops me to the same prompt as the host, but no longer in bold (specifically the prompt [user]#[container_id] is no longer in bold). I can tell I am in the container because of the file structure.
Question: What is happening? Am I one the right track to connecting to the database on the host? Why is it the same prompt and what is the significance of the change in font type from bold (host) to not bold (container)?
If it matters, the docker container is being created/ran inside a Vagrant machine.
The container id you normally see in your shell prompt is your container hostname. When you use --net=host, your container hostname is the same as your host's hostname. You have removed the normal network namespace that containers have. So the bash prompt with your container will look similar to the prompt on the host of you display the same fields on each. You can see the formatting of the prompt by checking the value of $PS1.
Edit: here's a comparison of different values of $PS1 from different base images (my host happens to be Debian):
$ echo $PS1
${debian_chroot:+($debian_chroot)}\u#\h:\w\$
$ docker run -it --rm debian:latest
root#4aca692dc29d:/# echo $PS1
${debian_chroot:+($debian_chroot)}\u#\h:\w\$
root#4aca692dc29d:/# exit
exit
$ docker run -it --rm ubuntu
root#b1eb8e51d672:/# echo $PS1
\[\e]0;\u#\h: \w\a\]${debian_chroot:+($debian_chroot)}\u#\h:\w\$
root#b1eb8e51d672:/# exit
exit
$ docker run -it --rm busybox
/ # echo $PS1
\w \$
/ # exit
$ docker run -it --rm centos
[root#abbfa9aa6968 /]# echo $PS1
[\u#\h \W]\$
[root#abbfa9aa6968 /]# exit
exit
I want to run a mysql container in Docker. The Dockerfile that I use is the Dockerfile defined in the official repo[here].
I only extended this Dockerfile with 2 more lines so I can import a init sql file, like this :
ADD my-init-file.sql /my-init-file.sql
CMD ["mysqld", "--init-file=/my-init-file.sql"]
I want to run this instance as a daemon but when I execute this command, from the documentation:
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=mysecretpassword -d mysql
The container exits automatically. I want to run it as a daemon so I can link apps(like a wordpress site) in another container to the mysql database.
Maybe I am missing something. Can anyone show me how ?
[EDIT] I forgot to say that I ran docker logs my-container after starting the container and there is no error :
Running mysql_install_db ...
Finished mysql_install_db
docker ps shows no running container.
My guess is the command executes successfully but the mysqld daemon does not start.
Your Dockerfile seems fine. Your init file may be buggy, though. If MySQL terminates, then the container will terminate.
The first debug step is to look at the logs:
docker logs some-mysql
You can use this whether the container is stopped or running. Hopefully, you'll see something obvious, like you missed some semicolons.
If the logs don't help, the next thing to try is to get inside the container and see what's happening first-hand
docker run -e MYSQL_ROOT_PASSWORD=mysecretpassword -it mysql /bin/bash
This will get you a Bash shell inside your container. Then you can run
mysqld --init-file=/my-init-file.sql
And see what happens. Maybe something in your init file tells MySQL to exit cleanly, so you get no logs but the command terminates.
Dmitri, after you made docker run with -d argument your container detached and already working as daemon if only CMD command not returned exit code.
You can check running containers by docker ps command.
You can check all containers by running docker ps -a.
Also i think you will need to open mysql port outside the container. You can do it with -P argument or better way to make communication between containers is docker links.