Docker container with Oracle DB startup issue

I am trying my hands on Docker for Oracle database. I used the docker image provided by Oracle to build a database and created a container. It was working fine, but later I realized that I needed to expose a port to the container. So, I did a commit of the current container changes and built a new image. I stopped the current container, and tried to start a new container with newly created image by exposing the port I wanted. While creating the container, it’s unable to start the DB because it’s unable to find some DB related files, i.e. spfile. Below are the steps that I followed:

  1. Commit current container
    $ docker commit -c “EXPOSE 587” 66917902ab38 oracle_database:v3
    sha256:00a9b783ca52771d696cf09e5e590f654fafb0ce44226339ade42a5ee554ec97
  1. Stop current container
    $ docker stop 66917902ab38

  2. Start a new container with newly created image
    $ docker run --name new_cdb -p 1522:1521 -p 5501:5500 -p 587:587 oracle_database:v3

It gives below error while starting the DB:

Database Information:
Global Database Name:cdb1
System Identifier(SID):cdb1
SQL*Plus: Release 12.2.0.1.0 Production on Sun Aug 20 04:41:48 2017
Copyright (c) 1982, 2016, Oracle. All rights reserved.
Connected to an idle instance.
SQL> ALTER SYSTEM SET control_files=‘/opt/oracle/oradata/cdb1/control01.ctl’ scope=spfile
*ERROR at line 1:
ORA-01034: ORACLE not available
Process ID: 0
Session ID: 0 Serial number: 0

It’s because database in containers have the vital files stored in volume (check the official documentation on volumes, if you will). So, when you commit the image, it is commited without the necessary files. You can remedy this situation with mapping the database files, using volumes while starting the container ( -v var/lib/docker/volumes/your_volume:/u01/app/oracle -this is just an example though). Hope this helped a little.