nerdexam
CompTIACompTIA

XK0-005 · Question #1695

XK0-005 Question #1695: Real Exam Question with Answer & Explanation

The correct answer is A: docker run -d --restart always -p 5432:5432 -v /home/db:/var/lib/postgresql postgresql:12. The command docker run -d --restart always -p 5432:5432 -v /home/db:/var/lib/postgresql postgresql:12 ensures that the PostgreSQL container is started in detached mode (-d), it restarts automatically on system startup (--restart always), mounts the host directory /home/db to /var

Scripting, Containers, and Automation

Question

An operations engineer is planning to start a container running a PostgreSQL database. The engineer wants the container to start automatically at system startup, mount the /home/db directory as /var/lib/postgresql inside the container, and expose port 5432 to the OS. Which of the following commands should the engineer run to achieve this task?

Options

  • Adocker run -d --restart always -p 5432:5432 -v /home/db:/var/lib/postgresql postgresql:12
  • Bdocker run -d --restart -p 5432:5432 --volume /var/lib/postgresql:/home/db postgresql:12
  • Cdocker run -d --attach --platform 5432:5432 --volume /home/db:/var/lib/postgresql postgresql:12
  • Ddocker run -d --init --restart --publish 5432:5432 --workdir /home/db:/var/lib/postgresql

Explanation

The command docker run -d --restart always -p 5432:5432 -v /home/db:/var/lib/postgresql postgresql:12 ensures that the PostgreSQL container is started in detached mode (-d), it restarts automatically on system startup (--restart always), mounts the host directory /home/db to /var/lib/postgresql, and exposes port 5432. This is a typical setup for running a database in a Docker container.

Topics

#Docker#Container deployment#Volume mapping#Port publishing

Community Discussion

No community discussion yet for this question.

Full XK0-005 PracticeBrowse All XK0-005 Questions