Do Docker containers remember commands that were previously executed?

Build and run the To-Do List sample app

  • 4 minutes to read

In the course of this tutorial, you will work with a simple to-do list manager that runs in Node.js. It's not a problem if you are not familiar with Node.js. No knowledge of JavaScript is required.

Your development team is currently quite small, and you are simply developing an app to design your Minimum Viable Product (MVP). You want to demonstrate how the app works and what it can do without worrying about how it works for a large team of multiple developers.

Get the app

Before you can run the application, you need the application source code on your computer. For actual projects, this is usually done by cloning the repository. However, a zip file containing the application is provided for this tutorial.

  1. Make sure that Docker for Windows or Docker Community Edition is installed on the local computer. For more information, see the Docker for Windows documentation. During the installation process, the ZIP file with the example is made available at the localhost address.

  2. Download the zip file. Open the zip file and extract the contents.

  3. Then use your favorite code editor to open the project. If you don't have an editor, you can use Visual Studio Code. You should see and the two subdirectories and.

Create the container image for the app

To create the application, you need a. A Dockerfile is just a text-based script with instructions that is used to create a container image. If you've already created Dockerfiles, you may notice some issues in the Dockerfile below. You don't have to worry about that. These are dealt with.

  1. Create a file named in the same folder as the file with the following contents.

    Make sure that the file does not have an extension such as. Some editors may add this extension automatically. However, this leads to an error in the next step.

  2. Open a terminal and navigate to the directory with the if you haven't already. Now use the command to create the container image.

    Alternatively, you can right-click on the Dockerfile file, Create image ... then specify the tag at the prompt.

    This command uses the Dockerfile to create a new container image. You may have noticed that some “layers” have been downloaded. That's because you told the generator that you want to start with the image. However, since this is not available on your computer, the image had to be downloaded first.

    After the image was downloaded, you copied your application and used it to install your application's dependencies. The directive sets the default command to be executed when a container is started from this image.

    Finally, your image will be marked with the flag. You can think of these as human readable names for the final image. Since you named the image, you can reference the image when you run a container.

    The one at the end of the command tells Docker to search for in the current directory.

Start an app container

Now that you have an image, run the application. To do this, use the command (you know this from before).

  1. Start your container using the command and set the name of the image you just created:

    Do you remember the flags and? You run the new container in "detached" mode (in the background) and create a mapping between port 3000 of the host and port 3000 of the container. Without the port mapping, you would not be able to access the application.

  2. After a few seconds, open http: // localhost: 3000 in your web browser. You should then see the app.

  3. Add an item or two and see if the app works as expected. You can mark items as complete or remove them. Your front end successfully stores items in the back end. It was easy and quick.

You should now have a working To Do List manager with a few items that you created on your own. Next, you'll make some changes and learn how to manage your containers.

If you look at the VS Code extension you should see your two containers that ran (this tutorial and the newly launched app container).


In this short section you learned the basics of creating a container image and created a Dockerfile for it. Once you've created an image, you've launched the container and seen the app running.

Next, you'll make a change to the app and learn how to update the running application with a new image. You will learn a few more useful commands.

Next Steps

Continue tutorial!