Get root access inside mssql docker container
Asked Answered
O

4

16

I created a MSSQL docker container based on the official image provided by Microsoft (https://hub.docker.com/_/microsoft-mssql-server).

I started a bash shell inside the running container and tried to delete some files.

sudo docker exec -it sql1 "bash"

Inside the container it is using the mssql account (by default).

And there seems to be some permission issues when I tried to delete the files.

rm -f *.csv
rm: cannot remove 'xxx.csv': Operation not permitted

How can I obtain the root permission to delete the file? I am not sure what default password I can use to run rm as root.

Thanks a lot!

Obeng answered 17/4, 2020 at 12:39 Comment(0)
B
24

You can specify the user as an argument:

sudo docker exec -it --user root sql1 "bash"
Baese answered 17/4, 2020 at 13:9 Comment(0)
M
3

I had a similar problem where the Docker container kept crashing, and the cause seems to be missing permissions for the server to run. If you are using docker-compose.yml, try the following. The user: root part should do the trick and run the container with root privilege:

version: "3.9"

services:
  mssql:
    image: mcr.microsoft.com/mssql/server:2022-latest
    container_name: mssql
    user: root
    environment:
      - ACCEPT_EULA=Y
      - SA_PASSWORD=YourPassword

PS: There may be a security concern when running the server as root so please chip in if anyone knows how to handle this. However, using root privilege seems to be accepted by Microsoft.

Migrant answered 8/3, 2023 at 21:31 Comment(0)
V
0

If you are on docker-compose

user:
      0:0
Vedda answered 9/2, 2023 at 16:58 Comment(0)
A
0

With user 0 you will log in as the root user

docker exec -u 0 -it container name /bin/bash
Anecdotist answered 6/8, 2024 at 9:52 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.