To have confidence that our Dockerized Elasticsearch container is working, we should first stop our existing Elasticsearch daemon:
$ sudo systemctl stop elasticsearch.service
$ sudo systemctl status elasticsearch.service
● elasticsearch.service - Elasticsearch
Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vend
Active: inactive (dead)
Docs: http://www.elastic.co
As a test, run the E2E tests on our API repository and make sure you get errors similar to Error: No Living connections. This means Elasticsearch is not running and our API cannot connect to it.
Now, use the docker run command to run the elasticsearch-oss image as a container:
$ docker run --name elasticsearch -e "discovery.type=single-node" -d -p 9200:9200 -p 9300:9300 docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4
Just as you can retrieve a list of Docker images available with docker images, you can retrieve a list of Docker containers using $ docker ps. Run the following command in a new terminal:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a415f4b646e3 docker.elastic.co/elasticsearch/elasticsearch-oss:6.2.4 "/usr/local/bin/dock\u2026" About an hour ago Up About an hour 0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp elasticsearch
Internally, Docker has added a writable layer on top of the elasticsearch-oss image, and stores it under a directory at /var/lib/docker/containers:
$ tree a415f4b646e3a715dc9fa446744934fc99ea33dd28761456381b9b7f6dcaf76b/
a415f4b646e3a715dc9fa446744934fc99ea33dd28761456381b9b7f6dcaf76b/
├── checkpoints
├── config.v2.json
├── a415f4b646e3a715dc9fa446744934fc99ea33dd28761456381b9b7f6dcaf76b-json.log
├── hostconfig.json
├── hostname
├── hosts
├── mounts
│ └── shm
├── resolv.conf
└── resolv.conf.hash
3 directories, 7 files
config.v2.json contains the metadata of the container, such as its status, its process ID (PID), when it was started, the image it is running from, its name, and its storage driver. <hash>-json.log stores the standard output when the container is running.
Now, with our container running, when we run our tests again, they are all passing! If we stop the container and run our tests again, they would, once again, fail:
$ docker stop a415f4b646e3
a415f4b646e3
$ yarn run test:e2e # This should fail
You can still view the stopped container using docker ps. However, by default, the docker ps command lists only running containers. You must use the -a flag to ensure that stopped containers are listed:
$ docker ps -a