Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How enable SQL Server Agent in docker container existing

I have a running SQL Server image on Docker, however I need to enable SQL Server Agent to run some jobs, but I have not succeeded. The main problem is that the container has quite a few databases and settings that need to be maintained. The command "docker run -e" MSSQL_AGENT_ENABLED = true ... "" is not useful to me because it creates a new container and I would lose the current configuration.

I used the following commands that allowed to enable the interface, but when running the job I get an error that SQL Server Agent is not enabled

exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Agent XPs',1
reconfigure 

The error generated when executing the job is the following

An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo) SQLServerAgent is not currently running so it cannot be notified of this action. (Microsoft SQL Server, Error: 22022)

I tried to start the SQL Server Agent with the command EXEC xp_servicecontrol N'START ', N'SQLServerAGENT', but it generates another error

StartService() returned error 1053, 'The service did not respond to the start or control request in a timely fashion.'

The question would be, how can I enable the SQL Server Agent in the container that is already running to be able to schedule jobs

like image 827
Miguel Bustamante Avatar asked Jan 20 '26 01:01

Miguel Bustamante


1 Answers

If you've already created a Docker container with something like SQL Server 2019 Developer edition:

$ docker run -e ACCEPT_EULA=Y -e MSSQL_PID=Developer -e MSSQL_SA_PASSWORD=YourStrongPassw0rd -p 1433:1433 -d mcr.microsoft.com/mssql/server:2019-latest
57301203bac57455a118e0dbe6ff392cb19313375c134050e6ecd77414555e7e

With reference to Configure SQL Server on Linux with the mssql-conf tool, get a root shell in the container:

$ docker exec -it --user root 57301203bac5 bash

Then enable SQL Agent in the configuration file and restart the SQL Server service:

root@57301203bac5:/# /opt/mssql/bin/mssql-conf set sqlagent.enabled true
SQL Server needs to be restarted in order to apply this setting. Please run
'systemctl restart mssql-server.service'.

root@57301203bac5:/# systemctl restart mssql-server.service

If you get an error message such as systemctl: command not found then just stop and start the container for the changes to take effect.

like image 58
AlwaysLearning Avatar answered Jan 22 '26 16:01

AlwaysLearning



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!