Analytics Vidhya
Published in

Analytics Vidhya

Deploy Your First Docker Container — Part 3

In last article, we learned how to run specific instance of Redis. Now we’ll learn further step to deploy your first docker container :

Step 5 : Persisting Data

After working with containers for a few days, Jane realises that the data stored keeps being removed when she deletes and re-creates a container. Jane needs the data to be persisted and reused when she recreates a container.

Containers are designed to be stateless. Binding directories (also known as volumes) is done using the option -v <host-dir>:<container-dir>. When a directory is mounted, the files which exist in that directory on the host can be accessed by the container and any data changed/written to the directory inside the container will be stored on the host. This allows you to upgrade or change containers without losing your data.

Using the Docker Hub documentation for Redis, Jane has investigated that the official Redis image stores logs and data into a /data directory.

Any data which needs to be saved on the Docker Host, and not inside containers, should be stored in /opt/docker/data/redis.

The complete command to solve the task is docker run -d --name redisMapped -v /opt/docker/data/redis:/data redis

Step 6 : Running A Container In The Foreground

Jane has been working with Redis as a background process. Jane wonders how containers work with foreground processes, such as ps or bash.

Previously, Jane used the -d to execute the container in a detached, background, state. Without specifying this, the container would run in the foreground. If Jane wanted to interact with the container (for example, to access a bash shell) she could include the options -it.

As well as defining whether the container runs in the background or foreground, certain images allow you to override the command used to launch the image. Being able to replace the default command makes it possible to have a single image that can be re-purposed in multiple ways. For example, the Ubuntu image can either run OS commands or run an interactive bash prompt using /bin/bash


The command docker run ubuntu ps launches an Ubuntu container and executes the command ps to view all the processes running in a container.

Using docker run -it ubuntu bash allows Jane to get access to a bash shell inside of a container.




Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem

Recommended from Medium

Learn JDBC By Project — Part VII

Introducing: Forge-CLI (beta) — Forge

Personal Kanban Part 2 — Personal Kanban with Trello

Angular Flex-Layout: Flexbox and Grid Layout for Angular Component

How to Generate a QR Code in C/C++

AWS Starter Kit — 2020 Edition

Microsoft SDE Interview

Dodging The Rabbit Hole That Vim Is

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kajal Rawal

Kajal Rawal

Programming isn’t about what you know; it’s about what you can figure out.

More from Medium

Run a Spring boot docker image on windows with a MySQL local database connection

Docker with NodeJS package.json

Simple Dockerfile to build nodejs application

Flask JWT based Authentication and Authorization Library Survey

Handle multiple databases in bitbucket Pipelines