Unable to execute the CMD command on docker for windows in the dockerfile.
I want to run couple of commands using the CMD, however, unable to run even a single command.
I have tried the follwoing, and nothing works...
1.
CMD "sqlcmd -S database -i C:\db\db_scripts\upgradescript.sql -U sa -P mypassword"
2.
RUN ["powershell", "-NoProfile", "-Command", "c:\db\db_scripts\script.ps1"]
3.
CMD ["cmd", "sqlcmd", "-S", "database", "-i", "C:\db\db_scripts\upgradescript.sql", "-U", "sa", "-P", "mypassword"]
4.
ARG arg1=database
ARG arg2=C:\db\db_scripts\upgradescript.sql
ARG arg3=sa
ARG arg4=mypassword!
RUN ["cmd", "-NoProfile", "-Command", "sqlcmd -S $env:arg1 -i $env:arg2 -U $env:arg3 -P $env:arg4"]
5.
RUN powershell.exe c:\db\db_scripts\script.ps1
6.
ENTRYPOINT ["powershell", "-NoProfile", "-Command", "sqlcmd"]
CMD ["-S database -i C:\db\db_scripts\upgradescript.sql -U sa -P mypassword"]
SUPPORTING FILES:
A. Script.ps1 (Used by 2 and 5)
cmd /c "sqlcmd -S database -i C:\db\db_scripts\upgradescript.sql -U sa -P mypassword"
B. Dockerfile
# escape=`
FROM microsoft/mssql-server-windows-developer
COPY db\* c:\db\
COPY db_scripts\* c:\db\db_scripts\
ENV attach_dbs="[{'dbName':'ABC','dbFiles':['C:\db\ABC.mdf','C:\db\ABC_Log.ldf']},{'dbName':'XYZ','dbFiles':['C:\db\XYZ.mdf','C:\db\XYZ_Log.ldf']}]"
CMD "sqlcmd -S database -i C:\db\db_scripts\upgradescript.sql -U sa -P mypassword"
Please note, I do not need to use "\\" because of the escape character.
OBSERVATIONS
The container starts and disappears after a few seconds.
If I remove the CMD part, the containers work just fine. I can get into the container and can run the above sqlcmd
command in cmd
shell.
What am I doing wrong, what's missing, any better approach etc. Could anyone give some guidance please? Thanks!
Edit:
Based on Josh's answer, the only way this ENTRYPOINT command is working for me is (sharing so others can benefit or even post better way of doing this)...
ENV arg1 database
ENV arg2 C:\db\db_scripts\upgradescript.sql
ENV arg3 sa
ENV arg4 mypassword
ENTRYPOINT ["powershell sleep(60); sqlcmd"]
CMD ["-S $env:arg1 -i $env:arg2 -U $env:arg3 -P $env:arg4"]