How can I use Drupal8 by using SQL Server with Docker - sql-server

I am trying use docker build drupal-8, but I want SQL Server to be my database
Now, I using docker-compose to setting but it's doesn't work. It's still only
here is my docker-compose.yml file txt
version: "2"
services:
web:
image: drupal:8
ports:
- "83:80"
links:
- db
restart: always
db:
image: microsoft/mssql-server-linux
volumes:
- mssqlTest:/var/opt/mssql/data
volumes:
mssqlTest:

Related

Docker compose - can't connect to SQL Server database in SQL Server Management Studio

I am trying to connect to my DB that has been created in my Docker Compose file. It looks like the DB has been successfully created but I am unable to connect to it using SQL Server management studio.
Here is my Docker Compose file:
version: "3.9"
services:
web:
image: ${DOCKER_REGISTRY-}umbracoapp
build:
context: .\umbracoapp
dockerfile: Dockerfile
ports:
- "8000:80"
depends_on:
- db
db:
image: "mcr.microsoft.com/mssql/server"
environment:
SA_PASSWORD: "Testing1234!!"
ACCEPT_EULA: "Y"
Thanks
To access the database from outside the bridge network that Docker creates, you need to map it's port to a port on the host.
In the container, MSSQL uses port 1433. If that port is available on your host, you can map it to 1433 on the host by adding 'ports' to your db service like this
db:
image: "mcr.microsoft.com/mssql/server"
ports:
- "1433:1433"
environment:
SA_PASSWORD: "Testing1234!!"
ACCEPT_EULA: "Y"

Running MS SQL server in docker refuses connection

I have issues connecting with MSSQL Server Management Studio to my running docker container.
A beginner in docker.
I have created a following docker-compose.yml file:
version: '3.4'
services:
sqlserver:
image: "mcr.microsoft.com/mssql/server:2017-latest"
volumes:
- /var/lib/docker/volumes/sql_volume/_data
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: "pa55w0rd!"
MSSQL_PID: "Express"
ports:
- "1533:1534"
adventureworks_service:
image: ${DOCKER_REGISTRY-}adventureworksservice
build:
context: .
dockerfile: AdventureWorks_Service/Dockerfile
this docker file should start a MSSQL Database and the adventureworks_service project located in my solution.
this docker-compose is located in it's own Docker project, in the solution. created with the "add docker support" for my Web API project
assuming everything is correctly setup, I should be able to connect to the sql server on localhost:1533, using SQL server authentication with login Express and password pa55w0rd!.
I get following error right after attempting to connect (no timeouts, etc.)
A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider : TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host) (Microsoft SQL Server, Error: 10054)
Does anyone know how I can access this server / container?
Thanks in advance
The port in mssql should be 1433 rather than 1534, try this
version: '3.4'
services:
sqlserver:
image: "mcr.microsoft.com/mssql/server:2017-latest"
volumes:
- /var/lib/docker/volumes/sql_volume/_data
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: "pa55w0rd!"
MSSQL_PID: "Express"
ports:
- "1433:1433" # the port behind should always be 1433
adventureworks_service:
image: ${DOCKER_REGISTRY-}adventureworksservice
build:
context: .
dockerfile: AdventureWorks_Service/Dockerfile
then your connection string should be like this
Data Source=sqlserver,1433;User Id=SA;Password=pa55w0rd!
Try adding network_mode: "host" to your compose file.
version: '3.4'
services:
sqlserver:
image: "mcr.microsoft.com/mssql/server:2017-latest"
volumes:
- /var/lib/docker/volumes/sql_volume/_data
environment:
ACCEPT_EULA: "Y"
SA_PASSWORD: "pa55w0rd!"
MSSQL_PID: "Express"
ports:
- "1533:1534"
network_mode: "host"
adventureworks_service:
image: ${DOCKER_REGISTRY-}adventureworksservice
build:
context: .
dockerfile: AdventureWorks_Service/Dockerfile

How can I run SQL commands against dockerized SQL Server via docker-compose?

I have a SQL Server running inside a Docker container. It is setup via docker-compose file and tied to my .NET Core API:
version: '3.4'
services:
appdb:
image: mcr.microsoft.com/mssql/server
container_name: ${SQL_SERVER_CONTAINER_NAME}
restart: unless-stopped
ports:
- "${SQL_SERVER_HOST_PORT}:1433"
environment:
SA_PASSWORD: ${SQL_SERVER_USER_PASSWORD}
ACCEPT_EULA: "Y"
volumes:
- ./../../.microsoft/data:/var/opt/mssql/data
- ./../../.microsoft/log:/var/opt/mssql/log
- ./../../.microsoft/secrets:/var/opt/mssql/secrets
demoapi.website:
image: ${DOCKER_REGISTRY-}demoapiwebsite
build:
context: .
dockerfile: DemoAPI.Website/Dockerfile
container_name: ${APP_NAME}-app
environment:
- ASPNETCORE_ENVIRONMENT=Development
- "ConnectionStrings__AppConnectionString=Server=${SQL_SERVER_CONTAINER_NAME},${SQL_SERVER_HOST_PORT}; Initial Catalog=${APP_NAME};User ID=${SQL_SERVER_USER_ID};Password=${SQL_SERVER_USER_PASSWORD}"
depends_on:
- appdb
ports:
- "8000:80"
I also have a bunch of SQL script files inside my .NET Core API project. These scripts basically define how to create and seed the database when the project is started.
What I would like to do is to execute these scripts somehow once the dockerized SQL Server is up and running. Is it possible to do this via the docker-compose file?
I see a lot of tutorials which use the actual .NET app and do this during the app start up with EF migrations, but I would prefer to get this done via docker-compose, if possible?

How to alter GitHub Docker-Compose.yml To use Informix DB for Portus?

I am attempting to make a secured repo for our internal docker registry. Github has a ready to go docker-compose however it is using MariaDB and Postgres as highlighted below.
What would be the best practice to utilize the same informix container to run 2 databases for the frontend and backend support of Portus & Docker Registry.
I feel I have to post the entire docker-compose yaml for context. I am also not clear on if i really need Clair for anything.
I am running this on a Open SUSE Leap 15 system. Thank you!
I have been messing around with this and as its written the registry and portus will not connect for some reason, but the underlining Databases seem to work fine and those are a bigger concern at this moment.
version: '2'
services:
portus:
build: .
image: opensuse/portus:development
command: bundle exec rails runner /srv/Portus/examples/development/compose/init.rb
environment:
- PORTUS_MACHINE_FQDN_VALUE=${MACHINE_FQDN}
- PORTUS_PUMA_HOST=0.0.0.0:3000
- PORTUS_CHECK_SSL_USAGE_ENABLED=false
- PORTUS_SECURITY_CLAIR_SERVER=http://clair:6060
- CCONFIG_PREFIX=PORTUS
- PORTUS_DB_HOST=db
- PORTUS_DB_PASSWORD=portus
- PORTUS_DB_POOL=5
- RAILS_SERVE_STATIC_FILES=true
ports:
- 3000:3000
depends_on:
- db
links:
- db
volumes:
- .:/srv/Portus
background:
image: opensuse/portus:development
entrypoint: bundle exec rails runner /srv/Portus/bin/background.rb
depends_on:
- portus
- db
environment:
- PORTUS_MACHINE_FQDN_VALUE=${MACHINE_FQDN}
- PORTUS_SECURITY_CLAIR_SERVER=http://clair:6060
# Theoretically not needed, but cconfig's been buggy on this...
- CCONFIG_PREFIX=PORTUS
- PORTUS_DB_HOST=db
- PORTUS_DB_PASSWORD=portus
- PORTUS_DB_POOL=5
volumes:
- .:/srv/Portus
links:
- db
webpack:
image: kkarczmarczyk/node-yarn:latest
command: bash /srv/Portus/examples/development/compose/bootstrap-webpack
working_dir: /srv/Portus
volumes:
- .:/srv/Portus
clair:
image: quay.io/coreos/clair:v2.0.2
restart: unless-stopped
depends_on:
- postgres
links:
- postgres
ports:
- "6060-6061:6060-6061"
volumes:
- /tmp:/tmp
- ./examples/compose/clair/clair.yml:/clair.yml
command: [-config, /clair.yml]
**db:
image: library/mariadb:10.0.23
command: mysqld --character-set-server=utf8 --collation-server=utf8_unicode_ci --init-connect='SET NAMES UTF8;' --innodb-flush-log-at-trx-commit=0
environment:
MYSQL_ROOT_PASSWORD: portus**
**postgres:
image: library/postgres:10-alpine
environment:
POSTGRES_PASSWORD: portus**
registry:
image: library/registry:2.6
environment:
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /registry_data
REGISTRY_STORAGE_DELETE_ENABLED: "true"
REGISTRY_HTTP_ADDR: 0.0.0.0:5000
REGISTRY_HTTP_DEBUG_ADDR: 0.0.0.0:5001
REGISTRY_AUTH_TOKEN_ROOTCERTBUNDLE: /etc/docker/registry/portus.crt
REGISTRY_AUTH_TOKEN_REALM: http://${MACHINE_FQDN}:3000/v2/token
REGISTRY_AUTH_TOKEN_SERVICE: ${MACHINE_FQDN}:${REGISTRY_PORT}
REGISTRY_AUTH_TOKEN_ISSUER: ${MACHINE_FQDN}
REGISTRY_NOTIFICATIONS_ENDPOINTS: >
- name: portus
url: http://${MACHINE_FQDN}:3000/v2/webhooks/events
timeout: 2000ms
threshold: 5
backoff: 1s
volumes:
- /registry_data
- ./examples/development/compose/portus.crt:/etc/docker/registry/portus.crt:ro
ports:
- ${REGISTRY_PORT}:5000
- 5001:5001
links:
- portus
The databases seem to run fine but I am still what i would consider a novice with docker-compose and informix on the setup side.
Any pointers or documentations recommendations would be most helpful as well.
unfortunately, Portus does not support informix DB. see this link

How to run golang-migrate with docker-compose?

In golang-migrate's documentation, it is stated that you can run this command to run all the migrations in one folder.
docker run -v {{ migration dir }}:/migrations --network host migrate/migrate
-path=/migrations/ -database postgres://localhost:5432/database up 2
How would you do this to fit the syntax of the new docker-compose, which discourages the use of --network?
And more importantly: How would you connect to a database in another container instead to one running in your localhost?
Adding this to your docker-compose.yml will do the trick:
db:
image: postgres
networks:
new:
aliases:
- database
environment:
POSTGRES_DB: mydbname
POSTGRES_USER: mydbuser
POSTGRES_PASSWORD: mydbpwd
ports:
- "5432"
migrate:
image: migrate/migrate
networks:
- new
volumes:
- .:/migrations
command: ["-path", "/migrations", "-database", "postgres://mydbuser:mydbpwd#database:5432/mydbname?sslmode=disable", "up", "3"]
links:
- db
networks:
new:
Instead of using the --network host option of docker run you set up a network called new. All the services inside that network gain access to each other through a defined alias (in the above example, you can access the db service through the database alias). Then, you can use that alias just like you would use localhost, that is, in place of an IP address. That explains this connection string:
"postgres://mydbuser:mydbpwd#database:5432/mydbname?sslmode=disable"
The answer provided by #Federico work for me at the beginning, nevertheless, I realised that I've been gotten a connect: connection refused the first time the docker-compose was run in brand new environment, but not the second one. This means that the migrate container runs before the Database is ready to process operations. Since, migrate/migrate from docker-hub runs the "migration" command whenever is ran, it's not possible to add a wait_for_it.sh script to wait for the db to be ready. So we have to add depends_on and a healthcheck tags to manage the order execution.
So this is my docker file:
version: '3.3'
services:
db:
image: postgres
networks:
new:
aliases:
- database
environment:
POSTGRES_DB: mydbname
POSTGRES_USER: mydbuser
POSTGRES_PASSWORD: mydbpwd
ports:
- "5432"
healthcheck:
test: pg_isready -U mydbuser -d mydbname
interval: 10s
timeout: 3s
retries: 5
migrate:
image: migrate/migrate
networks:
- new
volumes:
- .:/migrations
command: ["-path", "/migrations", "-database", "postgres://mydbuser:mydbpwd#database:5432/mydbname?sslmode=disable", "up", "3"]
links:
- db
depends_on:
- db
networks:
new:
As of Compose file formats version 2 you do not have to setup a network.
As stated in the docker networking documentation By default Compose sets up a single network for your app. Each container for a service joins the default network and is both reachable by other containers on that network, and discoverable by them at a hostname identical to the container name.
So in you case you could do something like:
version: '3.8'
services:
#note this databaseservice name is what we will use instead
#of localhost when using migrate as compose assigns
#the service name as host
#for example if we had another container in the same compose
#that wnated to access this service port 2000 we would have written
# databaseservicename:2000
databaseservicename:
image: postgres:13.3-alpine
restart: always
ports:
- "5432"
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: username
POSTGRES_DB: database
volumes:
- pgdata:/var/lib/postgresql/data
#if we had another container that wanted to access migrate container at let say
#port 1000
#and it's in the same compose file we would have written migrate:1000
migrate:
image: migrate/migrate
depends_on:
- databaseservicename
volumes:
- path/to/you/migration/folder/in/local/computer:/database
# here instead of localhost as the host we use databaseservicename as that is the name we gave to the postgres service
command:
[ "-path", "/database", "-database", "postgres://databaseusername:databasepassword#databaseservicename:5432/database?sslmode=disable", "up" ]
volumes:
pgdata:

Resources