Run commands inside a container already running

I’m using docker executor with DinD, and I was wondering if it’s possible to send commands to a container already running in the background.

Hello @jaquense , since you are running a Docker containter you can use docker commands.

List the running containers to get the containner id, run :

$ docker ps

With “docker ps” command you will get a list of running container with this informations: CONTAINER ID, IMAGE, COMMAND, CREATED, STATUS, PORTS, NAMES

Get the ID and run this command, you will get a terminal within the container and run your commands:

$ docker exec -it CONTAINER_ID /bin/bash

Ok, but is it possible to send a command, like for example pwd, in the same instruction?

I don’t want to type the command since it’s something that the CI server pipeline will take care of.

Try this

$ docker exec -it CONTAINER_ID pwd

Hi, I have the same question, but my container was created during pipeline jobs. So I tried your solution, but I’m still stuck. Do you have any ideas?