I have a docker image in which I want to run the following command :
echo "1" > /tmp/service.cfg
/bin/bash
How can I group and escape this command to run it within a docker container :
docker run -i -t debian/latest echo "1" > /tmp/service.cfg && /bin/bash
The command above doesn't works as it doesn't echo in the desired file first and then give me the hand in a shell...
Mounted Docker Socket EscapeIf somehow you find that the docker socket is mounted inside the docker container, you will be able to escape from it. This usually happen in docker containers that for some reason need to connect to docker daemon to perform actions.
docker exec You can leave the container with exit or ctrl-D .
Just Stopping the Container If you want to stop and exit the container, and are in an interactive, responsive shell - press ctrl+d to exit the session. You could as well type the exit command. TL;DR: press ctrl+c then ctrl+d - that means, keep the ctrl key pressed, type a c, and let go of ctrl.
WORKDIR instruction is used to set the working directory for all the subsequent Dockerfile instructions. Some frequently used instructions in a Dockerfile are RUN, ADD, CMD, ENTRYPOINT, and COPY. If the WORKDIR is not manually created, it gets created automatically during the processing of the instructions.
I found the solution, I needed to run the sh
command with the -c
flag like this :
docker run -i -t debian:latest sh -c 'echo "1" > /tmp/service.cfg && cat /tmp/service.cfg'
This returns 1 as expected...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With