0

I need to write a sh script that will run a docker container, and then execute some commands from within the container itself. Here is a very dumbed down example:

#!/bin/bash

cd someDir
docker run some_docker_image
echo "hello world"

The problem is, when I write it like this, and then try to execute the script, the docker container will be started, but the echo command will not be executed until I manually quit from the docker container (it is not executed within the docker container at all).

How do I forward the echo command from the example to the docker container? (echo here is just a placeholder for a list of commands that need to be executed from within the docker container)

Rebuilding the docker image is not an option

  • This is what heredocs are for. This isn't unique to docker, it's the same as how you feed further script content to a Python interpreter or a shell session or a SSH session or anything else. (Do note that you'll want to use the `-i` argument to `docker run`; `docker run -i <<'EOF'`, then `echo "hello world"`, then `EOF`). – Charles Duffy Jul 24 '23 at 19:17

0 Answers0