Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: sudo: command not found

I have an up and running containers and I wish to execute a database backup. Apparently, a simple command from the docker such as: sudo mkdir new_folder result in: bash: sudo: command not found

What have I tried (on an intuitive level) I accessed one of the running container with docker exec -i -t 434a38fedd69/bin/bash and RUN

apt-get update 
apt-get install sudo

when exit back to docker and tried to perform sudo mkdir new_folder but I got the same message bash: sudo: command not found

Baresp@adhg MINGW64 /c/Program Files/Docker Toolbox/postgre
$ mkdir new_folder
mkdir: cannot create directory ‘new_folder’: Permission denied

Baresp@adhg MINGW64 /c/Program Files/Docker Toolbox/postgre
$ sudo mkdir new_folder
bash: sudo: command not found

BTW, I'm not sure if this is relevant but the docker-compose file I was using is:

version: '2'

services:
postgres:
image: postgres
environment:
  POSTGRES_USER: postgres
  POSTGRES_PASSWORD: changeme
  PGDATA: /data/postgres
volumes:
   - /data/postgres:/data/postgres
ports:
  - "5432:5432"
networks:
  - postgres
restart: unless-stopped
container_name: xx_postgres

pgadmin:
links:
  - postgres:postgres
image: fenglc/pgadmin4
volumes:
   - /data/pgadmin:/root/.pgadmin
ports:
  - "5050:5050"
networks:
  - postgres
restart: unless-stopped
container_name: xx_pgadmin


networks:
postgres:
driver: bridge
like image 222
adhg Avatar asked Nov 27 '22 01:11

adhg


1 Answers

First, nothing you do in a docker exec is persistent outside of that particular running container (copy of the image), so if you want future containers run from that image to include sudo, those apt-get commands need to go into the Dockerfile that builds the image. Which, since you're using docker-compose, would require you to first make a Dockerfile and specify its location in the YAML.

Second, what do you mean "exit back to docker"? Nothing you do inside a container is going to have any effect on the system that Docker itself is running on, but it looks like you're running software install commands inside a Docker container and then expecting that to result in the newly-installed software being available outside the container on the Windows system that is running Docker.

like image 123
Mark Reed Avatar answered Feb 03 '23 20:02

Mark Reed