Home > Blockchain >  Batch file not executing a command
Batch file not executing a command

Time:06-29

I am trying to create a .bat file that will back-up the database inside the container. After the first command (that is used to enter the container) the next one is ignored.

docker exec -it CONTAINER_NAME /bin/bash
cd /var/opt/mssql/data

Any ideas why? If I'm trying to manually write cd /var/opt/mssql/data in the opened cmd it works.

CodePudding user response:

When running docker exec -it CONTAINER_NAME /bin/bash, you are opening a bash-shell INSIDE the docker container.

The next command, i.e. cd /var/opt/mssql/data, is only executed, if the previous command, docker exec -it CONTAINER_NAME /bin/bash has exited successfully, which means that the shell on the docker container has been closed/exited.

This means that cd /var/opt/mssql/data is then executed on the local machine and not inside the docker container.

To run a command inside the docker container, use the following command

docker exec -it CONTAINER_NAME /bin/bash -c "<command>"

Although it may be better to create a script inside the container during the build process or mount a script inside the docker container while starting the container and then simply call this script with the above mentioned command.

  • Related