Docker container not starting (docker start)

Docker

Docker Problem Overview


I created the container with the following command:

docker run -d -p 52022:22 basickarl/docker-git-test

Here are the commands:

root@basickarl:~# docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
root@basickarl:~# docker ps -a
CONTAINER ID        IMAGE                              COMMAND             CREATED             STATUS                           PORTS               NAMES
e4ac54468455        basickarl/docker-git-test:latest   "/bin/bash"         7 minutes ago       Exited (0) 26 seconds ago                            adoring_lumiere     
22d7c5d83871        basickarl/docker-git-test:latest   "/bin/bash"         2 hours ago         Exited (127) About an hour ago                       thirsty_wright      
root@basickarl:~# docker attach --sig-proxy=false e4
FATA[0000] You cannot attach to a stopped container, start it first 
root@basickarl:~# docker start e4
e4
root@basickarl:~# docker attach --sig-proxy=false e4
FATA[0000] You cannot attach to a stopped container, start it first 
root@basickarl:~# 

Not much to say really, I'm expecting the container to start and stay upp. Here are logs:

root@basickarl:~# docker logs e4
root@basickarl:~# 

Docker Solutions


Solution 1 - Docker

You are trying to run bash, an interactive shell that requires a tty in order to operate. It doesn't really make sense to run this in "detached" mode with -d, but you can do this by adding -it to the command line, which ensures that the container has a valid tty associated with it and that stdin remains connected:

docker run -it -d -p 52022:22 basickarl/docker-git-test

You would more commonly run some sort of long-lived non-interactive process (like sshd, or a web server, or a database server, or a process manager like systemd or supervisor) when starting detached containers.

If you are trying to run a service like sshd, you cannot simply run service ssh start. This will -- depending on the distribution you're running inside your container -- do one of two things:

  • It will try to contact a process manager like systemd or upstart to start the service. Because there is no service manager running, this will fail.

  • It will actually start sshd, but it will be started in the background. This means that (a) the service sshd start command exits, which means that (b) Docker considers your container to have failed, so it cleans everything up.

If you want to run just ssh in a container, consider an example like this.

If you want to run sshd and other processes inside the container, you will need to investigate some sort of process supervisor.

Solution 2 - Docker

What I need is to use Docker with MariaDb on different port /3301/ on my Ubuntu machine because I already had MySql installed and running on 3306.

To do this after half day searching did it using:

docker run -it -d -p 3301:3306 -v ~/mdbdata/mariaDb:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root --name mariaDb mariadb

This pulls the image with latest MariaDb, creates container called mariaDb, and run mysql on port 3301. All data of which is located in home directory in /mdbdata/mariaDb.

To login in mysql after that can use:

mysql -u root -proot -h 127.0.0.1 -P3301

Used sources are:

The answer of Iarks in this article /using -it -d was the key :) /

how-to-install-and-use-docker-on-ubuntu-16-04

installing-and-using-mariadb-via-docker

mariadb-and-docker-use-cases-part-1

Good luck all!

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbasickarlView Question on Stackoverflow
Solution 1 - DockerlarsksView Answer on Stackoverflow
Solution 2 - Dockerpanayot_kulchev_bgView Answer on Stackoverflow