Reputation: 9484
I am now trying to simulate the production environment.
Ultimate Goals:
1. Apache
2. php5
3. Microsoft SQL Server
4. Create database
5. Make database schema
6. Connect from website
3 of them I can simply achieves by DockerFile
and docker-compose.yml
Problem is 4th
DockerFile
FROM debian:7
RUN apt-get update
RUN apt-get install -y freetds-common freetds-bin unixodbc php5-sybase apache2
RUN mkdir /source
WORKDIR /source
COPY application ./applications
COPY assets ./assets
COPY pushnotification ./pushnotification
COPY system ./system
COPY uploads ./uploads
COPY web.config .
docker-compose.yml
version: '3'
services:
mssql:
image: microsoft/mssql-server-linux:latest
environment:
ACCEPT_EULA: Y
SA_PASSWORD: <password>
MSSQL_PID: Developer
restart: "always"
ports:
- "1433:1433"
backend:
container_name: gen365-cms
build:
context: .
dockerfile: DockerFile
links:
- mssql
ports:
- "8081:8080"
I am trying to create database according to manual
$ docker exec -it a3063bbff978 /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P phohHa0gyahh2Vah
1> select Name from sys.databases;
2> \q
3> ;
4> exit
Question:
How can I create database to my container
?
Upvotes: 5
Views: 3170
Reputation: 964
Why don't you create the SQL container, and then use SSMS and run whatever scripts are needed to create the database? Then, stop the container, and commit it to an image, and you'll be good to go with an image supporting delivery of n instances?
Upvotes: 0
Reputation: 1218
Create a Dockerfile for SQL Server and use COPY command to copy sql script file( with commands to create Databases and schema )and use RUN command to run the sql script while creating image and create the container from the Image. It will solve the problem.
Refer to the link below: https://github.com/twright-msft/mssql-node-docker-demo-app
Upvotes: 1