Exec sed command to a docker container Exec sed command to a docker container docker docker

Exec sed command to a docker container


Nehal is absolutely right, sed works creating a local file so you just need a different approach, which is commonly used on Linux: heredocs.

Taking just the first lines from the documentation, a here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program.

It can help us with docker exec as follows:

docker exec -i container_name bash <<EOFsed -ire '/URL_BASE = /c\api.myapiurl' /tmp/config.inigrep URL_BASE /tmp/config.ini# any other command you likeEOF

Be aware of the -t, which is commonly used running bash, because it allocates a pseudo-TTY, and we don't really need that.Also, to be safe always use absolute paths like /tmp/config.ini.