I have created one docker container using the following command:
# docker run -itd --name ssh -p "1111:22" <--Image Name-->
When I tried to list normally using command:
I tried also restart and start command but it's not working.
Related
I was following this guide on customizing MySQL databases in Docker, and ran this command multiple times after making tweaks to the mounted sql files:
docker run -d -p 3306:3306 --name my-mysql -v /Users/pneedham/dev/docker-testing/sql-scripts:/docker-entrypoint-initdb.d/ -e MYSQL_ROOT_PASSWORD=supersecret -e MYSQL_DATABASE=company mysql
On all subsequent executions of that command, I would see an error like this:
docker: Error response from daemon: Conflict. The container name "/my-mysql" is already in use by container "9dc103de93b7ad0166bb359645c12d49e0aa4a3f2330b5980e455cec24843663". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
What I'd like to know is whether that docker run command can be modified to auto-kill the previous container (if it exists)? Or if there is a different command that has the same desired result.
If I were to create a shell script to do that for me, I'd first run docker ps -aqf "name=mysql" and if there is any output, use that resulting container ID by running docker rm -f $containerID. And then run the original command.
docker run command has a --rm arguments that deletes the container after the run is completed. see the docs . So, just change your command to
docker run --rm -d -p 3306:3306 --name my-mysql -v /Users/pneedham/dev/docker-testing/sql-scripts:/docker-entrypoint-initdb.d/ -e MYSQL_ROOT_PASSWORD=supersecret -e MYSQL_DATABASE=company mysql
I have created a docker container for my Go program and I am able to run that code within that container successfully. I have created a docker network to run that code. I have used the following command:
docker run --network network_name -it go_program Github_repo -l 10000 -secio
Now to test my program I am trying to provide a maximum fixed cpu resource(40%) to the container. I have used the following command to do that:
sudo docker run -it --cpus=".4" ubuntu
But after that when I try to run my program it always says it doesn't recognize the command:
shihab#shihab-VirtualBox:~$ sudo docker run -it --cpus=".4" ubuntu
root#67637cc7edd1:/# sudo docker run --network network_name -it go_program Github_repo -l 10000 -secio
bash: sudo: command not found
How can I solve this issue? Thanks.
Yes , becuase when you run sudo docker run -it --cpus=".4" ubuntu
you go into the container , and then you run the second command inside the container which is not working
Instead you need to just run one command , all in one:
sudo docker run --network network_name --cpus=".4" -it go_program Github_repo -l 10000 -secio
here I assume that go_program is the docker image containing your go program
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'm creating a rabbitmq container with the -v option to add a volume, the weird part is that if I don't add the --hostname the container is no getting the information of the volume, for example:
I create a volume like this:
docker volume create --name rabbit
Later I verify that the volume is created
docker volume ls
Then I create the container like this:
docker run --name rabbitprueba -P -p 55555:15672 -d -v rabbit:/var/lib/rabbitmq rabbitmq:3.6.10-management
I enter to localhost:55555 and enter user and password, then I create a simple queue, I return to my machine and stop and remove the container:
docker stop rabbitprueba
docker rm rabbitprueba
when I run the same command:
docker run --name rabbitprueba -P -p 55555:15672 -d -v rabbit:/var/lib/rabbitmq rabbitmq:3.6.10-management
The queue that I created is gone but if I repeat the same steps (stop container and remove it) and add to the command the --hostname the queue is not removed:
docker run --hostname rabbitprueba --name rabbitprueba -P -p 55555:15672 -d -v rabbit:/var/lib/rabbitmq rabbitmq:3.6.10-management
Why this is happening?, Am I doing something wrong?,
So you are doing nothing wrong, but you are assuming the problem to be with docker. The problem is how rabbitmq saves its data.
When you launch a rabbitmq container using below command
docker run -it rabbitmq:latest
You will notice in docker logs a line showing
Database directory at /var/lib/rabbitmq/mnesia/rabbit#51267ba4cc9f is empty. Initialising from scratch...
Next run:
Database directory at /var/lib/rabbitmq/mnesia/rabbit#5e9c67b4d6ed is empty. Initialising from scratch...
So you can see it creates a folder based on the hostname. Now if i run
docker run -it --hostname mymq rabbitmq
And the log would show
Database directory at /var/lib/rabbitmq/mnesia/rabbit#mymq is empty. Initialising from scratch...
So that is what is happening here. Not a problem with volume, but just the way rabbitmq works. It is possible for you to change the name of this config using environment variables like below
docker run -it -e "RABBITMQ_NODENAME=mq#localhost" rabbitmq
And logs would now show
Database directory at /var/lib/rabbitmq/mnesia/mq#localhost is empty. Initialising from scratch...
I am running Kurento on debian through Docker with
docker run -d --name kurento -p 8888:8888 kurento/kurento-media-server
That starts the kurento server. Problem is : I need to configure /etc/kurento/modules/kurento/WebRtcEndpoint.conf.ini file that runs in docker and I have no idea on how to access it since it runs in background
When I run docker in interactive mode:
docker run -it --name kurento -p 8888:8888 kurento/kurento-media-server
the server runs in foreground, and I cannot do anything except a CTRL+C ( I tried ctrl+Z to put in in BG process)
Any idea ?
If you have to input an initial configuration file, the best way is by using a volume when starting:
docker run -d --name kurento -p 8888:8888 -v /etc/kurento/modules/kurento/:/path/to/your/env/kurento kurento/kurento-media-server
and inside /path/to/your/env/kurento will be your WebRtcEndpoint.conf.ini file
If you just want to jump inside the machine and tinker around, you can 'exec bash':
docker exec -it kurento /bin/bash
Once your container is started and running, you can create a bash session in that container with below command:
docker exec -ti <container_name> bash