Solved!! Docker-Compose SQL Server database persist data after host restart

Solved!! Docker-Compose SQL Server database persist data after host restart

Click to Watch Video

Problem: There is nothing like losing data in the SQL Server Docker Container after it stopped. As a rule of thumb, it's always good practice to back up data to several locations in case you need to role-back the database to a healthy known state or just to restore the database.

This short article, yet to the point will show how docker-compose.yaml file need to be configured in order to persist data after a restart.

Solution: Remember, when you don't have a Dockerfile in the root folder, there is no need to build the image, in this case, we will start our Docker Container by simply typing: sudo docker-compose up #that is it, needed to start the service.

In your docker-compose.yaml file
- define the version of docker-compose # Remember, docker-compose comes as a separate install. You will need to install docker-compose utility in order to utilize the CLI.
- After defining the version, define the services
- under services, define database image: #the database image you will be using in your Docker Container
- most important don't forget to provide the environment variables for a user and the password.
- Under the environment: define a password and Accept the EULA

[NB] The bind section under volumes will automatically sync the files in the Docker Container and the Host, if you have other jobs that back up the data to other location, this is the best place to define as the source.

[Troubleshoot]: Pay attention to the spacing, Yaml files are finicky when it comes to spacing, there is one space between "name definition" or "version:" and the actual version string. 

See the code below:

version: "3.2"
services:
   NameOfYourService:
        image: "NameOfTheImageYouWishToUse"
        container_name: GiveContainerName
        ports:
             - "HostPortToBindToDockerContainer:DockerContainerPort"
        enviroment:
             - USERNAME_PASSWORD=YourPasswordHere
             - ACCEPT_EULA="Y"
        restart: always
        volumes:
             - type: bind
                source: /locationOnHost
                target:  /targetLocationOnDockerContainer

 

 

 


Edit this Article
sql server docker-compose file Dockerfile sql docker-compose errors asp.net core 3.1 Docker Docker published
Was this page helpful?
Yes Yes! this solution to the problem was helpful. No No! this solution to the problem was not helpful.. Leave ErnesTech Feedback.Feedback
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Your Session is Ending
Login to Continue

© 2021 - ErnesTech - Privacy