Explore Courses Blog Tutorials Interview Questions
0 votes
in DevOps and Agile by (2.3k points)

I just started to get into docker recently. I've been trying to deploy a WorPress container using docker-compose.

Now my issue is that i am not able to ssh into my container , i want to be able to check out the directories and the files present inside my container. 

I used this command :

$ docker-compose run < container name > ls -la

But it didn't do anything. 

Can someone help me out with this ? I want to run commands on a console and traverse directories inside my container . 

Is their a standard way to do this?


1 Answer

+1 vote
by (6.9k points)
selected by
Best answer

Now when you say SSH I assume just get into the container from the host and if so , yes there is a standard method for exactly what you have described.

First you will need to get the name of your container or its ID.

Use :

$ docker ps

This will list all the docker containers running in your host. Copy either the name or the ID and use it the command below: 

$ docker exec -it < Name_of_container > bash

Using the above command you can get inside your container and use a terminal to run commands and traverse through the directories of your container. 

But if you want to use SSH it self you can also do that, but it is not the standard way to get into a container.

Type in the commands given below :

apt-get update

apt-get install openssh-server

mkdir /var/run/sshd

chmod 0755 /var/run/sshd


useradd --create-home --shell /bin/bash --groups sudo username ## includes 'sudo'

passwd username ## Enter a password

Now you will be able to SSH into the docker container.

Also If you want to become more adept with docker you can check this Docker training course . You will be trained by industry professionals who have years of experience in docker. Or you can refer to the docker tutorial for beginners blog.

Browse Categories