所以我正在尝试设置一个docker-compose文件,并在其中进行一些数据初始化。但是,当我在终端中执行docker-compose up
时(Windows 1尝试了一个bash)我得到了sh: 1: ./entrypoint: not found
,尽管它在我向命令添加ls
时显示了该文件。
mssql_1 | data
mssql_1 | entrypoint.sh
mssql_1 | init.sql
mssql_1 | table
我的docker-compose文件:
version: '2.1'
services:
mssqldata:
image: microsoft/mssql-server-linux:latest
entrypoint: /bin/bash
mssql:
image: microsoft/mssql-server-linux:latest
ports:
- 1433:1433
volumes:
- /var/opt/mssql
- ./sql:/usr/src/app
working_dir: /usr/src/app
command: sh -c 'chmod +x ./entrypoint.sh; ./entrypoint.sh & /opt/mssql/bin/sqlservr;'
environment:
ACCEPT_EULA: Y
SA_PASSWORD: P@55w0rd
volumes_from:
- mssqldata
文件夹结构:
docker-compose.yml
sql/
data/
table/
entrypoint.sh
init.sql
答案 0 :(得分:0)
在我看来,这应该发生在dockerfile而不是docker-compose.yml文件中。通常,docker-compose背后的想法是运行多容器应用程序并使多容器应用程序中的容器相互通信。因此,例如在您的上下文中,可能是让三个容器与asp.net + MSSQL + IIS容器的其他容器进行通信。
无论如何你想要实现的目标都可以在dockerfile中完成 我会尽量为你编写这个dockerfile。这是dockerfile:
FROM microsoft/mssql-server-linux:latest
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
EXPOSE 1433
ADD entrypoint.sh /entrypoint.sh
COPY entrypoint.sh /entrypoint.sh
# I suggest you add starting : "/opt/mssql/bin/sqlservr" to the entrypoint.sh script it would simplify things a bit.
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
以下是您需要的docker-compose.yml文件:
version: '2'
services:
ms-sql-server-container:
image: mssql-container:latest
# This refers to the docker container created by building our dockerfile with:
# docker build -t mssql-container .
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=P@55w0rd
volumes:
- ./sql:/usr/src/app
# I don't really understand the reason for the second volume that you had if you can kindly explain, then I can edit my answer to accomodate the second volume
# if I think that you need it.
ports:
- 1433:1433
如果有效,请告诉我。