docker-compose plain ubuntu container

The following article explains how to start and keep running a plain ubuntu container in the background.

During everyday software development, you might want to share a folder in host machine along with a unix based container like Debian or Ubuntu container to verify if certain things works as expected in headless mode or remote server. Hence this blog post explains how to start and keep running an empty Ubuntu container without installing any additional package or service and the current directory of host machine will be mounted at /var/host_machine_folder/

Create file "my-ubuntu-container.yml" with the following contents

################
version: '2'

services:
  my-ubuntu:
    container_name: my-ubuntu
    image: "ubuntu:latest"
    command: tail -f /dev/null
    volumes:
      - .:/var/host_machine_folder/
    environment:
      # This is set in host system and the value from host system is passed on to the container
      - MY_HOST_VALUE
      # This is a new environment variable with explicit value
      - MY_NEW_VALUE=3456
################

Create a plain text file "my-test-file.txt" with the following contents

#############
This really works!!!
#############

Structure should look like this:

root-directory
    |->my-ubuntu-container.yml
    |->my-test-file.txt

Start the ubuntu docker container:

docker-compose -f ./my-ubuntu-container.yml -p myubuntucontainer up -d

Connect the running container, print the text file, environment variables and exit:

docker exec -it my-ubuntu /bin/bash

cat /var/host_machine_folder/my-test-file.txt

echo $MY_NEW_VALUE

echo $MY_HOST_VALUE

exit

Stop the ubuntu docker container:

docker-compose -f ./my-ubuntu-container.yml -p myubuntucontainer down -v

Comments

Popular posts from this blog

JSON with curl and jq

Import self signed in Linux for Chrome / Chromium headless testing

Colima - Drop In replacement for Docker Desktop for Mac and Linux