I am trying to run SQL Server on ubuntu as a docker container using stranded microsoft/mssql-server-linux:latest docker image. For the data persistence I am mapping a volume from my host (having ext4 file system) to container using -v option in docker run command like below
docker run -it -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=######' -p 1433:1433
-v /var/opt/database:/var/opt/mssql/data microsoft/mssql-server-linux
Container is running just fine and i am able to connect to the database. But I do not want to store data on my host because of the growing size of the database and for swarm reasons. Now I thought to run a NFS server on some other machine and mount the nfs directory onto my docker host and then use that nfs dir on the volume mapping now the volume mapping is
-v /var/nfs/database:/var/opt/mssql/data
where /var/nfs/database is a nfs mount dir on the docker host. Now when I start the container I get the following error
2017-08-18 10:15:53.98 spid5s FCB::Open failed: Could not open file /var/opt/mssql/data/master.mdf for file number 1. OS error: 87(The parameter is incorrect.).
2017-08-18 10:15:53.98 spid5s Error: 5120, Severity: 16, State: 101.
2017-08-18 10:15:53.98 spid5s Unable to open the physical file "/var/opt/mssql/data/master.mdf". Operating system error 87: "87(The parameter is incorrect.)".
2017-08-18 10:15:54.13 spid5s Error: 17204, Severity: 16, State: 1.
2017-08-18 10:15:54.13 spid5s FCB::Open failed: Could not open file /var/opt/mssql/data/mastlog.ldf for file number 2. OS error: 87(The parameter is incorrect.).
2017-08-18 10:15:54.13 spid5s Error: 5120, Severity: 16, State: 101.
2017-08-18 10:15:54.13 spid5s Unable to open the physical file "/var/opt/mssql/data/mastlog.ldf". Operating system error 87: "87(The parameter is incorrect.)".
I have given all the permissions to database files. Below is the nfs mount snippet
sharedstorageIp:/var/nfs nfs4 443G 47G 375G 11% /var/nfs
The release notes explain that you can't do this:
Hosting database files on a NFS server is not supported in this
release. This includes using NFS for shared disk failover clustering
as well as databases on non-clustered instances. We are working on
enabling NFS server support in the upcoming releases.
Hosting database files on a networked path is not trivial, given the demands the database has for reliability. Hosting files on SMB shares wasn't possible until version 2.2 of the protocol.
Related
I have a SQL server which is triggered inside docker container from gitlab. Following yaml file does that :
services:
- name: mcr.microsoft.com/mssql/server:2019-latest
alias: mssql
variables:
MSSQL_HOST: microsoft-mssql-server-linux
ACCEPT_EULA: Y
MSSQL_COLLATION: Latin1_General_CS_AS
SA_PASSWORD: yourStrong(!)Password
Now when i am starting this pipeline its giving error in running the sql script saying that login failed for user SA . Error is as :
$ /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P
"yourStrong(!)Password" -i Scripts/DBScript.sql Sqlcmd: Error:
Microsoft ODBC Driver 17 for SQL Server : Login failed for user 'SA'..
Cleaning up file based variables ERROR: Job failed: command terminated
with exit code 1
This error gets resolved once i remove the collation "MSSQL_COLLATION:Latin1_General_CS_AS" from the yaml file.
This explains that i am not able to change MSSQL Serve collation.
Note: Container spawned by Gitlab is Linux Container which is also installing docker image of "mcr.microsoft.com/mssql/server:2019-latest".
Any idea how to change Collation level at MS SQL server level.
Use case:
I want to start SQL Server via docker on my mac for test and dev purposes.
As I do not want to loose my databases switching docker containers I want to use volumes.
Using docker volumes I can do that.
docker run --name 'mssql' -e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=SuperSecret' -p 1433:1433 -v mssqldata:/var/opt/mssql -d mcr.microsoft.com/mssql/server
But on mac the volume data is also stored inside the VM.
So next I tried to setup a docker compose configuration to store files on my favorite place.
version: '3'
volumes:
dbdata:
driver: local
driver_opts:
type: 'none'
o: 'bind'
device: '/Users/rausch/Documents/docker-volumes/mssql/data'
services:
sql1:
image: "mcr.microsoft.com/mssql/server"
ports:
- 1433:1433
environment:
PATH: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
ACCEPT_EULA: Y
SA_PASSWORD: 1sa!1234
MSSQL_PID: Standard
volumes:
- dbdata:/var/opt/mssql
Starting this with
docker compose -f myconfig.yml up
The sql server starts and start copy the files to my defined location
But the docker image exists with error.
Here the output:
Creating volume "documents_dbdata" with local driver
Creating documents_sql1_1 ... done
Attaching to documents_sql1_1
sql1_1 | SQL Server 2019 will run as non-root by default.
sql1_1 | This container is running as user mssql.
sql1_1 | To learn more visit https://go.microsoft.com/fwlink/?linkid=2099216.
sql1_1 | 2020-05-30 07:27:18.60 Server Setup step is copying system data file 'C:\templatedata\master.mdf' to '/var/opt/mssql/data/master.mdf'.
2020-05-30 07:27:19.67 Server Did not find an existing master data file /var/opt/mssql/data/master.mdf, copying the missing default master and other system database files. If you have moved the database location, but not moved the database files, startup may fail. To repair: shutdown SQL Server, move the master database to configured location, and restart.
2020-05-30 07:27:19.70 Server Setup step is copying system data file 'C:\templatedata\mastlog.ldf' to '/var/opt/mssql/data/mastlog.ldf'.
2020-05-30 07:27:19.79 Server Setup step is copying system data file 'C:\templatedata\model.mdf' to '/var/opt/mssql/data/model.mdf'.
2020-05-30 07:27:19.98 Server Setup step is copying system data file 'C:\templatedata\modellog.ldf' to '/var/opt/mssql/data/modellog.ldf'.
2020-05-30 07:27:20.17 Server Setup step is copying system data file 'C:\templatedata\msdbdata.mdf' to '/var/opt/mssql/data/msdbdata.mdf'.
2020-05-30 07:27:20.47 Server Setup step is copying system data file 'C:\templatedata\msdblog.ldf' to '/var/opt/mssql/data/msdblog.ldf'.
2020-05-30 07:27:20.55 Server Setup step is FORCE copying system data file 'C:\templatedata\model_replicatedmaster.mdf' to '/var/opt/mssql/data/model_replicatedmaster.mdf'.
2020-05-30 07:27:20.70 Server Setup step is FORCE copying system data file 'C:\templatedata\model_replicatedmaster.ldf' to '/var/opt/mssql/data/model_replicatedmaster.ldf'.
2020-05-30 07:27:20.78 Server Setup step is FORCE copying system data file 'C:\templatedata\model_msdbdata.mdf' to '/var/opt/mssql/data/model_msdbdata.mdf'.
2020-05-30 07:27:21.02 Server Setup step is FORCE copying system data file 'C:\templatedata\model_msdblog.ldf' to '/var/opt/mssql/data/model_msdblog.ldf'.
2020-05-30 07:27:22.99 Server Microsoft SQL Server 2019 (RTM-CU4) (KB4548597) - 15.0.4033.1 (X64)
sql1_1 Mar 14 2020 16:10:35
sql1_1 Copyright (C) 2019 Microsoft Corporation
sql1_1 Standard Edition (64-bit) on Linux (Ubuntu 18.04.4 LTS) <X64>
2020-05-30 07:27:23.01 Server UTC adjustment: 0:00
2020-05-30 07:27:23.02 Server (c) Microsoft Corporation.
2020-05-30 07:27:23.03 Server All rights reserved.
2020-05-30 07:27:23.04 Server Server process ID is 36.
2020-05-30 07:27:23.05 Server Logging SQL Server messages in file '/var/opt/mssql/log/errorlog'.
2020-05-30 07:27:23.06 Server Registry startup parameters:
sql1_1 -d /var/opt/mssql/data/master.mdf
sql1_1 -l /var/opt/mssql/data/mastlog.ldf
sql1_1 -e /var/opt/mssql/log/errorlog
2020-05-30 07:27:23.10 Server Error: 17113, Severity: 16, State: 1.
2020-05-30 07:27:23.10 Server Error 87(The parameter is incorrect.) occurred while opening file '/var/opt/mssql/data/master.mdf' to obtain configuration information at startup. An invalid startup option might have caused the error. Verify your startup options, and correct or remove them if necessary.
documents_sql1_1 exited with code 1
So, anyone can tell me what I do wrong?
I was able to get it to start on macOS using a Docker volume. Note my compose.yml file requires at least version 3.2 to allow the service's volumes definition to work:
version: "3.2"
services:
sql1:
image: "mcr.microsoft.com/mssql/server"
ports:
- 1433:1433
environment:
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
ACCEPT_EULA: Y
SA_PASSWORD: 1sa!1234
MSSQL_PID: Standard
volumes:
- type: volume
source: mssql
target: /var/opt/mssql
volumes:
mssql:
external:
name: mssql
I then launched the container with:
$ docker volume create mssql
mssql
$ docker volume inspect mssql
[
{
"CreatedAt": "2020-05-30T09:36:31Z",
"Driver": "local",
"Labels": {},
"Mountpoint": "/var/lib/docker/volumes/mssql/_data",
"Name": "mssql",
"Options": {},
"Scope": "local"
}
]
$ docker-compose -f compose.yml up
# lots of startup log...
Hope this helps.
I'm following this guide to restore a database backup
https://learn.microsoft.com/en-us/sql/linux/tutorial-restore-backup-in-sql-server-container?view=sql-server-ver15
I used docker cp command to copy the DB backup files to the container
docker exec -it SQLContainer mkdir /var/opt/mssql/backup
docker cp MyDb.bak SQLContainer:/var/opt/mssql/backup/
However when trying to restore the DB by running the following query in SSMS, an error message is shown
RESTORE DATABASE MyDB FROM DISK='/var/opt/mssql/backup/MyDB.bak'
Operating system error 5(Access is denied.).
I tried copying using docker cp -a, which sets file ownership to same as destination, but I got this error.
docker cp -a MyDb.bak SQLContainer:/var/opt/mssql/backup/
Error response from daemon: getent unable to find entry "mssql" in passwd database
I'm using Microsoft's image and I don't know the password for root user, the container runs using mssql user, so chown doesn't work either. How can I change the file permissions so DB restore works?
Turns out when I copied the database backup files from the Windows host to the Ubuntu machine, the files were owned by root user and all other users didn't have read permission.
Adding read permission to the file before copying to the docker container works and the server was able to read the files.
sudo chmod a+r MyDb.bak
sudo docker cp MyDb.bak SQLContainer:/var/opt/mssql/backup/
I had a similar issue just today, about the same time as this incident, just attaching MDF and LDF files.
By doing the chmod go+w before copying files without the -a I was able to get SQL Server to treat them as writeable. Prior to that I was getting error messages whenever any update was performed.
I'm running mssql server windows developer editon on docker, and I'll like to backup my database, so that every time I spin up a container, I don't have to recreate my databases and Re-Bootstrap. I've tried mounting a volume to my physical system, I keep getting the error
container aa8b9.. encountered an error during CreateProcess: failure in a Windows system call: The system cannot find the file specified.
The command I used was
docker run -d -p 1433:1433 -e sa_password=testing1234 -e ACCEPT_EULA=Y microsoft/mssql-server-windows-developer -v "C:\test\Microsoft SQL Server":"C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\DATA\"
I'm trying to change the default data directory for MSSQL Server RC1 2017 after installation and setup in linux (Ubuntu-16.10).
I used the following command to set the default data directory. Then restarted the mssql server.
sudo /opt/mssql/bin/mssql-conf set filelocation.defaultdatadir /mnt/var/opt/mssql/data/
systemctl restart mssql-server.service
After this I tried to create a simple database "test"
sqlcmd -s localhost -U sa -P "someStrongPassword" -Q "CREATE DATABASE test"
The error returned is as follows:
MODIFY FILE encountered operating system error 31(A device attached to
the system is not functioning.) while attempting to expand the
physical file '/mnt/var/opt/mssql/data/test.mdf'.
CREATE DATABASE
failed. Some file names listed could not be created. Check related
errors.
The error log indicates an OS error:
/mnt/var/opt/mssql/data/test.mdf: Operating system error 31(A device
attached to the system is not functioning.) encountered.
I cannot mount the data directory by any means. The permissions to "/mnt" directory are set to 777 too. Changing the default data directory to any other folder, works perfectly fine. Is this a known or recent bug with mssql server?
Yes, there is an issue with using remote storage through NFS and SMB that came up in CTP 2.1 and was not yet fixed in RC1. See release notes: https://learn.microsoft.com/en-us/sql/linux/sql-server-linux-release-notes#a-idrc1-rc1-july-2017-a
The only workarounds are to use local storage or CTP 2.0. We are working on a fix. Release ETA is TBD ATM.